@decocms/blocks 7.71.3 → 7.71.4
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 +1 -1
- package/src/cms/resolve.test.ts +75 -13
- package/src/cms/resolve.ts +39 -21
- package/src/cms/schema.ts +5 -1
- package/src/hooks/Image.test.ts +36 -0
- package/src/hooks/Image.tsx +7 -4
package/package.json
CHANGED
package/src/cms/resolve.test.ts
CHANGED
|
@@ -842,8 +842,15 @@ describe("extractSeoFromProps — commerce jsonLD structured data", () => {
|
|
|
842
842
|
// Highest-position breadcrumb item wins.
|
|
843
843
|
expect(seo.canonical).toBe("https://x.com/a/b");
|
|
844
844
|
expect(seo.noIndexing).toBe(false);
|
|
845
|
-
expect(seo.jsonLDs).toHaveLength(
|
|
846
|
-
expect(seo.jsonLDs?.[0]).toMatchObject({
|
|
845
|
+
expect(seo.jsonLDs).toHaveLength(2);
|
|
846
|
+
expect(seo.jsonLDs?.[0]).toMatchObject({
|
|
847
|
+
"@context": "https://schema.org",
|
|
848
|
+
"@type": "ItemList",
|
|
849
|
+
});
|
|
850
|
+
expect(seo.jsonLDs?.[1]).toMatchObject({
|
|
851
|
+
"@context": "https://schema.org",
|
|
852
|
+
"@type": "BreadcrumbList",
|
|
853
|
+
});
|
|
847
854
|
});
|
|
848
855
|
|
|
849
856
|
it("emits the product image and JSON-LD for a PDP", () => {
|
|
@@ -873,7 +880,7 @@ describe("extractSeoFromProps — commerce jsonLD structured data", () => {
|
|
|
873
880
|
});
|
|
874
881
|
expect(seo.title).toBe("Manual Title");
|
|
875
882
|
expect(seo.canonical).toBe("https://x.com/manual");
|
|
876
|
-
expect(seo.jsonLDs).toHaveLength(
|
|
883
|
+
expect(seo.jsonLDs).toHaveLength(2);
|
|
877
884
|
});
|
|
878
885
|
|
|
879
886
|
it("omits structured data for humans when ignoreStructuredData is set", () => {
|
|
@@ -893,7 +900,7 @@ describe("extractSeoFromProps — commerce jsonLD structured data", () => {
|
|
|
893
900
|
{ jsonLD: plp(), configJsonLD: { ignoreStructuredData: true } },
|
|
894
901
|
{ isEager: true },
|
|
895
902
|
);
|
|
896
|
-
expect(seo.jsonLDs).toHaveLength(
|
|
903
|
+
expect(seo.jsonLDs).toHaveLength(2);
|
|
897
904
|
expect(seo.title).toBe("PLP Title");
|
|
898
905
|
});
|
|
899
906
|
|
|
@@ -927,18 +934,71 @@ describe("extractSeoFromProps — commerce jsonLD structured data", () => {
|
|
|
927
934
|
expect(seo.jsonLDs).toBe(existing);
|
|
928
935
|
});
|
|
929
936
|
|
|
930
|
-
it("
|
|
931
|
-
const
|
|
932
|
-
|
|
937
|
+
it("emits a compact ItemList (position/url/name), not the whole listing page", () => {
|
|
938
|
+
const heavy = {
|
|
939
|
+
"@type": "Product",
|
|
940
|
+
name: "SKU name",
|
|
941
|
+
url: "https://x.com/p1/p",
|
|
942
|
+
isVariantOf: { name: "Product 1", hasVariant: [{ sku: "1" }, { sku: "2" }] },
|
|
943
|
+
additionalProperty: [{ name: "cluster", value: "42" }],
|
|
944
|
+
image: [{ url: "https://x.com/1.jpg" }],
|
|
945
|
+
video: [{ "@type": "VideoObject" }],
|
|
946
|
+
};
|
|
947
|
+
const seo = extractSeoFromProps({
|
|
948
|
+
jsonLD: plp({
|
|
949
|
+
products: [heavy, { "@type": "Product", name: "P2", url: "https://x.com/p2/p" }],
|
|
950
|
+
}),
|
|
951
|
+
});
|
|
952
|
+
expect(seo.jsonLDs?.[0]).toEqual({
|
|
953
|
+
"@context": "https://schema.org",
|
|
954
|
+
"@type": "ItemList",
|
|
955
|
+
numberOfItems: 2,
|
|
956
|
+
itemListElement: [
|
|
957
|
+
{ "@type": "ListItem", position: 1, url: "https://x.com/p1/p", name: "Product 1" },
|
|
958
|
+
{ "@type": "ListItem", position: 2, url: "https://x.com/p2/p", name: "P2" },
|
|
959
|
+
],
|
|
933
960
|
});
|
|
961
|
+
const json = JSON.stringify(seo.jsonLDs);
|
|
962
|
+
expect(json).not.toContain("hasVariant");
|
|
963
|
+
expect(json).not.toContain("additionalProperty");
|
|
964
|
+
expect(json).not.toContain("VideoObject");
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
it("points ListItems at the canonical product URL and drops items without one", () => {
|
|
934
968
|
const seo = extractSeoFromProps({
|
|
935
|
-
jsonLD:
|
|
936
|
-
|
|
969
|
+
jsonLD: plp({
|
|
970
|
+
products: [
|
|
971
|
+
{
|
|
972
|
+
name: "SKU A",
|
|
973
|
+
url: "https://x.com/a/p?skuId=1",
|
|
974
|
+
isVariantOf: { name: "A", url: "https://x.com/a/p" },
|
|
975
|
+
},
|
|
976
|
+
{ name: "No URL" },
|
|
977
|
+
{ name: "B", url: "https://x.com/b/p?skuId=2" },
|
|
978
|
+
],
|
|
979
|
+
}),
|
|
937
980
|
});
|
|
938
|
-
expect(seo.jsonLDs?.[0].
|
|
939
|
-
|
|
981
|
+
expect(seo.jsonLDs?.[0].itemListElement).toEqual([
|
|
982
|
+
{ "@type": "ListItem", position: 1, url: "https://x.com/a/p", name: "A" },
|
|
983
|
+
{ "@type": "ListItem", position: 2, url: "https://x.com/b/p?skuId=2", name: "B" },
|
|
984
|
+
]);
|
|
985
|
+
expect(seo.jsonLDs?.[0].numberOfItems).toBe(2);
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
it("omits the BreadcrumbList when the listing has no breadcrumb", () => {
|
|
989
|
+
const seo = extractSeoFromProps({ jsonLD: plp({ breadcrumb: undefined }) });
|
|
990
|
+
expect(seo.jsonLDs).toHaveLength(1);
|
|
991
|
+
expect(seo.jsonLDs?.[0]).toMatchObject({ "@type": "ItemList" });
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
it("omitVariants empties PDP variants without mutating the source", () => {
|
|
995
|
+
const source = pdp({
|
|
996
|
+
product: { "@type": "Product", name: "P1", isVariantOf: { hasVariant: [{ sku: "1" }] } },
|
|
997
|
+
});
|
|
998
|
+
const seo = extractSeoFromProps({ jsonLD: source, omitVariants: true });
|
|
999
|
+
expect(seo.jsonLDs?.[0].product.isVariantOf.hasVariant).toEqual([]);
|
|
940
1000
|
// biome-ignore lint/suspicious/noExplicitAny: test fixture
|
|
941
|
-
expect((source.
|
|
1001
|
+
expect((source.product as any).isVariantOf.hasVariant).toHaveLength(1);
|
|
942
1002
|
});
|
|
943
1003
|
});
|
|
944
1004
|
|
|
@@ -1258,7 +1318,9 @@ describe("layoutCacheKey — the resolved-layout cache is segmented by device",
|
|
|
1258
1318
|
// navigation.
|
|
1259
1319
|
|
|
1260
1320
|
it("mobile, tablet and desktop are three distinct keys", () => {
|
|
1261
|
-
const keys = [MOBILE_UA, TABLET_UA, DESKTOP_UA].map((ua) =>
|
|
1321
|
+
const keys = [MOBILE_UA, TABLET_UA, DESKTOP_UA].map((ua) =>
|
|
1322
|
+
layoutCacheKey(KEY, { userAgent: ua }),
|
|
1323
|
+
);
|
|
1262
1324
|
expect(new Set(keys).size).toBe(3);
|
|
1263
1325
|
});
|
|
1264
1326
|
|
package/src/cms/resolve.ts
CHANGED
|
@@ -1981,30 +1981,53 @@ function canonicalFromBreadcrumb(breadcrumb: unknown): string | undefined {
|
|
|
1981
1981
|
}
|
|
1982
1982
|
|
|
1983
1983
|
/**
|
|
1984
|
-
* Shallow-prune a
|
|
1984
|
+
* Shallow-prune a PDP `jsonLD` before emitting it as structured data.
|
|
1985
1985
|
* Clones only when a prune option is set (the common path emits as-is), so a
|
|
1986
1986
|
* jsonLD shared with a body section is never mutated out from under it.
|
|
1987
1987
|
*/
|
|
1988
1988
|
function pruneCommerceJsonLD(
|
|
1989
1989
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1990
1990
|
jsonLD: Record<string, any>,
|
|
1991
|
-
opts: {
|
|
1991
|
+
opts: { omitVariants: boolean },
|
|
1992
1992
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1993
1993
|
): Record<string, any> {
|
|
1994
|
-
if (!opts.
|
|
1994
|
+
if (!opts.omitVariants || !jsonLD.product?.isVariantOf?.hasVariant) return jsonLD;
|
|
1995
1995
|
const clone = structuredClone(jsonLD);
|
|
1996
|
-
|
|
1997
|
-
for (const product of clone.products) {
|
|
1998
|
-
product.video = undefined;
|
|
1999
|
-
for (const variant of product.isVariantOf?.hasVariant ?? []) variant.video = undefined;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
if (opts.omitVariants && clone.product?.isVariantOf?.hasVariant) {
|
|
2003
|
-
clone.product.isVariantOf.hasVariant = [];
|
|
2004
|
-
}
|
|
1996
|
+
clone.product.isVariantOf.hasVariant = [];
|
|
2005
1997
|
return clone;
|
|
2006
1998
|
}
|
|
2007
1999
|
|
|
2000
|
+
/**
|
|
2001
|
+
* schema.org structured data for a listing page: an `ItemList` of
|
|
2002
|
+
* position/url/name (what search engines read on category pages) plus the
|
|
2003
|
+
* `BreadcrumbList`. Emitting the resolved ProductListingPage itself is not
|
|
2004
|
+
* schema.org (no such type, no `@context`) and inlines every product with
|
|
2005
|
+
* variants/specs/images — multiple MB per page, in the HTML *and* in the
|
|
2006
|
+
* serialized route data, which pushes Workers past their memory limit.
|
|
2007
|
+
*/
|
|
2008
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2009
|
+
function plpStructuredData(plp: Record<string, any>): Record<string, unknown>[] {
|
|
2010
|
+
// Canonical product URL first: `url` is the SKU URL (`/p?skuId=N`), which
|
|
2011
|
+
// canonicalises elsewhere. Items without a URL are dropped (Google requires
|
|
2012
|
+
// `url` on summary-page items) before numbering, so positions stay contiguous.
|
|
2013
|
+
const itemListElement = (plp.products as any[]) // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
2014
|
+
.map((p) => ({ url: p.isVariantOf?.url ?? p.url, name: p.isVariantOf?.name ?? p.name }))
|
|
2015
|
+
.filter((item) => item.url)
|
|
2016
|
+
.map((item, i) => ({ "@type": "ListItem", position: i + 1, ...item }));
|
|
2017
|
+
const out: Record<string, unknown>[] = [
|
|
2018
|
+
{
|
|
2019
|
+
"@context": "https://schema.org",
|
|
2020
|
+
"@type": "ItemList",
|
|
2021
|
+
numberOfItems: itemListElement.length,
|
|
2022
|
+
itemListElement,
|
|
2023
|
+
},
|
|
2024
|
+
];
|
|
2025
|
+
if (plp.breadcrumb?.itemListElement?.length) {
|
|
2026
|
+
out.push({ ...plp.breadcrumb, "@context": "https://schema.org" });
|
|
2027
|
+
}
|
|
2028
|
+
return out;
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2008
2031
|
/**
|
|
2009
2032
|
* Derive SEO metadata from a commerce `jsonLD` data source (a resolved
|
|
2010
2033
|
* ProductListingPage / ProductDetailsPage), mirroring the deco-cx
|
|
@@ -2062,18 +2085,13 @@ function deriveCommerceSeoFromJsonLD(
|
|
|
2062
2085
|
// humans only; crawlers (and the `?__deco_ssr=1` audit override) still get it
|
|
2063
2086
|
// so indexing/rich results are unaffected. An empty page contributes no
|
|
2064
2087
|
// ItemList regardless.
|
|
2065
|
-
const configJsonLD = props.configJsonLD as
|
|
2066
|
-
| { ignoreStructuredData?: boolean; removeVideos?: boolean }
|
|
2067
|
-
| undefined;
|
|
2068
2088
|
const ignore = sectionIgnoresStructuredData(props);
|
|
2069
2089
|
if ((ignore && !isEager) || isEmpty) return;
|
|
2070
2090
|
|
|
2071
|
-
seo.jsonLDs =
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
omitVariants: props.omitVariants === true
|
|
2075
|
-
}),
|
|
2076
|
-
];
|
|
2091
|
+
seo.jsonLDs =
|
|
2092
|
+
type === "ProductListingPage"
|
|
2093
|
+
? plpStructuredData(jsonLD)
|
|
2094
|
+
: [pruneCommerceJsonLD(jsonLD, { omitVariants: props.omitVariants === true })];
|
|
2077
2095
|
}
|
|
2078
2096
|
|
|
2079
2097
|
/**
|
package/src/cms/schema.ts
CHANGED
|
@@ -882,7 +882,11 @@ function buildFrameworkSections(sectionAnyOf: any[], loaderUnion: any[]) {
|
|
|
882
882
|
type: "object",
|
|
883
883
|
title: "Structured Data",
|
|
884
884
|
properties: {
|
|
885
|
-
removeVideos: {
|
|
885
|
+
removeVideos: {
|
|
886
|
+
type: "boolean",
|
|
887
|
+
title: "Remove videos (deprecated)",
|
|
888
|
+
description: "No effect: listing structured data is an ItemList, which carries no videos.",
|
|
889
|
+
},
|
|
886
890
|
ignoreStructuredData: {
|
|
887
891
|
type: "boolean",
|
|
888
892
|
title: "Ignore Structured Data",
|
package/src/hooks/Image.test.ts
CHANGED
|
@@ -85,6 +85,34 @@ describe("getOptimizedMediaUrl", () => {
|
|
|
85
85
|
expect(result).toContain("fit=cover");
|
|
86
86
|
expect(result).toContain("src=https://cdn.example.com/foo.jpg");
|
|
87
87
|
});
|
|
88
|
+
|
|
89
|
+
it("strips the legacy decoims.com host so the CDN doesn't fetch itself (508)", () => {
|
|
90
|
+
const result = getOptimizedMediaUrl({
|
|
91
|
+
originalSrc: "https://decoims.com/site/2026/09/banner.png",
|
|
92
|
+
width: 100,
|
|
93
|
+
fit: "cover",
|
|
94
|
+
});
|
|
95
|
+
expect(result).toContain("&src=site/2026/09/banner.png");
|
|
96
|
+
expect(result).not.toContain("src=https://decoims.com/");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("strips decoims.com and drops its query string", () => {
|
|
100
|
+
const result = getOptimizedMediaUrl({
|
|
101
|
+
originalSrc: "https://decoims.com/site/a.png?v=2",
|
|
102
|
+
width: 100,
|
|
103
|
+
fit: "cover",
|
|
104
|
+
});
|
|
105
|
+
expect(result).toMatch(/&src=site\/a\.png$/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("only strips a leading Deco host", () => {
|
|
109
|
+
const result = getOptimizedMediaUrl({
|
|
110
|
+
originalSrc: "https://cdn.example.com/https://decoims.com/x.png",
|
|
111
|
+
width: 100,
|
|
112
|
+
fit: "cover",
|
|
113
|
+
});
|
|
114
|
+
expect(result).toContain("&src=https://cdn.example.com/https://decoims.com/x.png");
|
|
115
|
+
});
|
|
88
116
|
});
|
|
89
117
|
|
|
90
118
|
describe("getSrcSet", () => {
|
|
@@ -183,3 +211,11 @@ describe("registerImageQuality", () => {
|
|
|
183
211
|
expect(getImageQuality()).toBeUndefined();
|
|
184
212
|
});
|
|
185
213
|
});
|
|
214
|
+
|
|
215
|
+
describe("getSrcSet — legacy decoims.com sources", () => {
|
|
216
|
+
it("strips decoims.com from every srcset entry", () => {
|
|
217
|
+
const result = getSrcSet("https://decoims.com/site/b.png", 200, 100, "cover") ?? "";
|
|
218
|
+
expect(result).not.toContain("src=https://decoims.com/");
|
|
219
|
+
for (const entry of result.split(", ")) expect(entry).toContain("&src=site/b.png");
|
|
220
|
+
});
|
|
221
|
+
});
|
package/src/hooks/Image.tsx
CHANGED
|
@@ -5,8 +5,11 @@ import { forwardRef } from "react";
|
|
|
5
5
|
// Known asset prefixes that get stripped to produce a relative src path
|
|
6
6
|
// -------------------------------------------------------------------------
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// decocache, S3, and decoims.com — the legacy default image CDN (pre-#495).
|
|
9
|
+
// Decofiles are full of decoims URLs; passing one as `src=` to a Deco CDN makes
|
|
10
|
+
// it fetch itself → 508 Loop Detected. Anchored: only a leading host is stripped.
|
|
11
|
+
const DECO_ASSET_PREFIX_RE =
|
|
12
|
+
/^https:\/\/(?:assets\.decocache\.com|deco-sites-assets\.s3\.sa-east-1\.amazonaws\.com|decoims\.com)\//;
|
|
10
13
|
|
|
11
14
|
// -------------------------------------------------------------------------
|
|
12
15
|
// Configurable CDN domain
|
|
@@ -132,7 +135,7 @@ function optimizeShopify(originalSrc: string, width: number, height?: number): s
|
|
|
132
135
|
/**
|
|
133
136
|
* Builds an optimized image URL.
|
|
134
137
|
*
|
|
135
|
-
* For Deco-hosted images (decocache / S3), strips the known prefix and
|
|
138
|
+
* For Deco-hosted images (decocache / S3 / decoims), strips the known prefix and
|
|
136
139
|
* routes through the Deco image CDN for edge resize + format conversion.
|
|
137
140
|
*
|
|
138
141
|
* For platform-specific images (VTEX, Shopify), rewrites the URL using
|
|
@@ -169,7 +172,7 @@ export function getOptimizedMediaUrl(opts: OptimizationOptions): string {
|
|
|
169
172
|
return optimizeShopify(originalSrc, width, height);
|
|
170
173
|
}
|
|
171
174
|
|
|
172
|
-
let imageSource = originalSrc.replace(
|
|
175
|
+
let imageSource = originalSrc.replace(DECO_ASSET_PREFIX_RE, "").split("?")[0];
|
|
173
176
|
|
|
174
177
|
// Already on the image CDN — strip the host so we don't proxy through ourselves.
|
|
175
178
|
const cdnPrefix = `https://${imageCdnDomain}/`;
|