@decocms/blocks 7.77.0 → 7.77.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks",
3
- "version": "7.77.0",
3
+ "version": "7.77.2",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -540,6 +540,28 @@ describe("shouldDeferSection — admin is the source of truth", () => {
540
540
  expect(shouldDeferSection(section, 0, mkCfg(), false)).toBe(true);
541
541
  });
542
542
 
543
+ it("does NOT defer a Lazy wrapper carrying `loading: \"eager\"`", () => {
544
+ // Fresh's Lazy.tsx short-circuits on this prop and renders the inner
545
+ // section inline, so the wrapper is not a deferral at all. Decofiles
546
+ // migrated from Fresh carry it on the named `Footer` block.
547
+ const section = { ...lazyWrap({ __resolveType: "site/sections/Footer.tsx" }), loading: "eager" };
548
+ expect(shouldDeferSection(section, 0, mkCfg(), false)).toBe(false);
549
+ });
550
+
551
+ it("still defers a Lazy wrapper with `loading: \"lazy\"` or no loading prop", () => {
552
+ const inner = { __resolveType: "site/sections/Hero.tsx" };
553
+ expect(shouldDeferSection({ ...lazyWrap(inner), loading: "lazy" }, 0, mkCfg(), false)).toBe(true);
554
+ expect(shouldDeferSection(lazyWrap(inner), 0, mkCfg(), false)).toBe(true);
555
+ });
556
+
557
+ it("an eager Lazy wrapping a lazy Lazy still defers (inner wins)", () => {
558
+ const nested = {
559
+ ...lazyWrap(lazyWrap({ __resolveType: "site/sections/Hero.tsx" })),
560
+ loading: "eager",
561
+ };
562
+ expect(shouldDeferSection(nested, 0, mkCfg(), false)).toBe(true);
563
+ });
564
+
543
565
  it("renders a non-⚡ section eagerly regardless of position (default Infinity)", () => {
544
566
  const section = { __resolveType: "site/sections/SeoText.tsx" };
545
567
  // Position 5 used to auto-defer with the old foldThreshold=3 — now SSR.
@@ -1639,6 +1639,22 @@ function resolveFinalSectionKey(section: unknown, matcherCtx?: MatcherContext):
1639
1639
  * and return true if a deferral wrapper (Lazy.tsx or Deferred.tsx) is found
1640
1640
  * at any level. This is used by shouldDeferSection to determine if the CMS
1641
1641
  * editor intended this section to be deferred.
1642
+ *
1643
+ * A `Lazy` wrapper carrying `loading: "eager"` is NOT a deferral: on Deco for
1644
+ * Fresh that prop short-circuits the wrapper's own loader, which awaits the
1645
+ * inner section and renders it inline, with no FallbackWrapper —
1646
+ * `website/sections/Rendering/Lazy.tsx`:
1647
+ *
1648
+ * ```ts
1649
+ * const shouldRender = loading === "eager" || shouldForceRender({ … });
1650
+ * if (shouldRender) return { loading: "eager", section: await section() };
1651
+ * ```
1652
+ *
1653
+ * Decofiles migrated from Fresh carry that prop (a named `Footer` block whose
1654
+ * root is `Lazy.tsx` + `loading: "eager"` is the common shape), so ignoring it
1655
+ * turns a section prod server-renders into a skeleton that only materializes
1656
+ * client-side. Honouring it keeps the wrapper's meaning identical on both
1657
+ * runtimes.
1642
1658
  */
1643
1659
  function isCmsDeferralWrapped(section: unknown, matcherCtx?: MatcherContext): boolean {
1644
1660
  if (!section || typeof section !== "object") return false;
@@ -1651,6 +1667,15 @@ function isCmsDeferralWrapped(section: unknown, matcherCtx?: MatcherContext): bo
1651
1667
  if (!rt) return false;
1652
1668
 
1653
1669
  if (rt === WELL_KNOWN_TYPES.LAZY || rt === WELL_KNOWN_TYPES.DEFERRED) {
1670
+ // `loading: "eager"` cancels the deferral at this level. Keep walking
1671
+ // inward so a nested wrapper further down still counts, which is what
1672
+ // Fresh does when it awaits the inner section.
1673
+ if (current.loading === "eager") {
1674
+ const inner = current.section ?? current.sections;
1675
+ if (!inner || typeof inner !== "object" || Array.isArray(inner)) return false;
1676
+ current = inner as Record<string, unknown>;
1677
+ continue;
1678
+ }
1654
1679
  return true;
1655
1680
  }
1656
1681
 
@@ -237,3 +237,30 @@ describe("getSrcSet — legacy decoims.com sources", () => {
237
237
  for (const entry of result.split(", ")) expect(entry).toContain("&src=site/b.png");
238
238
  });
239
239
  });
240
+
241
+ describe("getOptimizedMediaUrl — Nuvemshop CDN", () => {
242
+ const SRC = "https://dcdn-us.mitiendanube.com/stores/008/336/778/products/3-76a3e88b446d6a938417912361162212-1024-1024.webp";
243
+ const at = (width: number) => getOptimizedMediaUrl({ originalSrc: SRC, width, fit: "cover" });
244
+ const base = SRC.replace(/-1024-1024\.webp$/, "");
245
+
246
+ it("serves the CDN's own fixed size that covers the width (no deco image proxy, which 403s it)", () => {
247
+ expect(at(50)).toBe(`${base}-50-0.webp`);
248
+ expect(at(287)).toBe(`${base}-320-0.webp`);
249
+ expect(at(480)).toBe(`${base}-480-0.webp`);
250
+ expect(at(574)).toBe(`${base}-640-0.webp`);
251
+ expect(at(700)).toBe(`${base}-1024-1024.webp`);
252
+ expect(at(4000)).toBe(`${base}-1024-1024.webp`);
253
+ });
254
+
255
+ it("keeps the original extension and works from any size variant", () => {
256
+ const jpg = "https://acdn-us.mitiendanube.com/stores/003/520/762/products/cadeira-1-480-0.jpg";
257
+ expect(getOptimizedMediaUrl({ originalSrc: jpg, width: 100, fit: "cover" })).toBe(
258
+ "https://acdn-us.mitiendanube.com/stores/003/520/762/products/cadeira-1-100-0.jpg",
259
+ );
260
+ });
261
+
262
+ it("leaves non-product Nuvemshop URLs to the default path", () => {
263
+ const logo = "https://dcdn-us.mitiendanube.com/stores/008/336/778/themes/common/logo.png";
264
+ expect(getOptimizedMediaUrl({ originalSrc: logo, width: 100, fit: "cover" })).toContain("/image?");
265
+ });
266
+ });
@@ -131,6 +131,19 @@ function optimizeShopify(originalSrc: string, width: number, height?: number): s
131
131
  return url.href;
132
132
  }
133
133
 
134
+ // Nuvemshop's product CDN serves only fixed sizes, picked by a filename suffix
135
+ // (`…-480-0.webp`, `…-1024-1024.webp`); any other size answers 403, and so does
136
+ // the deco image proxy for this host.
137
+ const NUVEMSHOP_IMAGE_RE =
138
+ /^(https:\/\/[a-z0-9-]+\.mitiendanube\.com\/stores\/.+\/products\/.+)-\d+-\d+\.(\w+)$/;
139
+ const NUVEMSHOP_SIZES = [50, 100, 240, 320, 480, 640];
140
+
141
+ function optimizeNuvemshop(match: RegExpMatchArray, width: number): string {
142
+ const [, base, ext] = match;
143
+ const size = NUVEMSHOP_SIZES.find((s) => s >= width);
144
+ return `${base}-${size ? `${size}-0` : "1024-1024"}.${ext}`;
145
+ }
146
+
134
147
  // -------------------------------------------------------------------------
135
148
  // Core optimization function
136
149
  // Ported from deco-cx/apps website/components/Image.tsx
@@ -142,7 +155,7 @@ function optimizeShopify(originalSrc: string, width: number, height?: number): s
142
155
  * For Deco-hosted images (decocache / S3 / decoims), strips the known prefix and
143
156
  * routes through the Deco image CDN for edge resize + format conversion.
144
157
  *
145
- * For platform-specific images (VTEX, Shopify), rewrites the URL using
158
+ * For platform-specific images (VTEX, Shopify, Nuvemshop), rewrites the URL using
146
159
  * the platform's native resize params — no CDN proxy needed.
147
160
  *
148
161
  * Data URIs are returned as-is.
@@ -176,6 +189,9 @@ export function getOptimizedMediaUrl(opts: OptimizationOptions): string {
176
189
  return optimizeShopify(originalSrc, width, height);
177
190
  }
178
191
 
192
+ const nuvemshop = originalSrc.match(NUVEMSHOP_IMAGE_RE);
193
+ if (nuvemshop) return optimizeNuvemshop(nuvemshop, width);
194
+
179
195
  let imageSource = originalSrc.replace(DECO_ASSET_PREFIX_RE, "").split("?")[0];
180
196
  if (CLOUDFLARE_CDNS.has(imageCdnDomain)) imageSource = imageSource.replace(DECOIMS_PREFIX_RE, "");
181
197