From fee4b114bfd68d48dfa675d01e4b48e2f99a95e8 Mon Sep 17 00:00:00 2001 From: Jamie Willis Date: Sat, 12 Apr 2025 12:22:03 +0100 Subject: [PATCH] made CookieWithMeta lazy too, it pulls in time --- core/src/main/scala/sttp/tapir/Codec.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/sttp/tapir/Codec.scala b/core/src/main/scala/sttp/tapir/Codec.scala index a98c57cf2c..2e146cb6a0 100644 --- a/core/src/main/scala/sttp/tapir/Codec.scala +++ b/core/src/main/scala/sttp/tapir/Codec.scala @@ -641,8 +641,10 @@ object Codec extends CodecExtensions with CodecExtensions2 with FormCodecMacros case Right(r) => DecodeResult.Value(r) } - implicit val cookieWithMeta: Codec[String, CookieWithMeta, TextPlain] = Codec.string.mapDecode(decodeCookieWithMeta)(_.toString) - implicit val cookiesWithMeta: Codec[List[String], List[CookieWithMeta], TextPlain] = Codec.list(cookieWithMeta) + // These are marked as lazy as they involve scala-java-time constructs, which massively inflate the bundle size for scala.js applications, even if + // they are unused within the program. By marking them lazy, it allows them to be *tree shaken* and removed by the optimiser. + implicit lazy val cookieWithMeta: Codec[String, CookieWithMeta, TextPlain] = Codec.string.mapDecode(decodeCookieWithMeta)(_.toString) + implicit lazy val cookiesWithMeta: Codec[List[String], List[CookieWithMeta], TextPlain] = Codec.list(cookieWithMeta) // raw tuples