@decocms/blocks 7.62.1 → 7.62.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 +1 -1
- package/src/cms/resolve.test.ts +44 -0
- package/src/cms/resolve.ts +25 -10
package/package.json
CHANGED
package/src/cms/resolve.test.ts
CHANGED
|
@@ -239,6 +239,50 @@ describe("commerce loader auto-injects URL search params as props", () => {
|
|
|
239
239
|
});
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
+
it("strips tracking params from __pageUrl and never injects them as props", async () => {
|
|
243
|
+
const calls: Array<Record<string, unknown>> = [];
|
|
244
|
+
registerCommerceLoader(KEY, async (props: Record<string, unknown>) => {
|
|
245
|
+
calls.push({ ...props });
|
|
246
|
+
return null;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
await resolveValue({ __resolveType: KEY, slug: "sabonete" }, undefined, {
|
|
250
|
+
url: "https://store.com/produto/sabonete/p?skuId=12345&utm_source=google&gclid=abc&srsltid=xyz",
|
|
251
|
+
path: "/produto/sabonete/p",
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
expect(calls[0]).toMatchObject({
|
|
255
|
+
slug: "sabonete",
|
|
256
|
+
skuId: "12345",
|
|
257
|
+
__pageUrl: "https://store.com/produto/sabonete/p?skuId=12345",
|
|
258
|
+
});
|
|
259
|
+
expect(calls[0]).not.toHaveProperty("utm_source");
|
|
260
|
+
expect(calls[0]).not.toHaveProperty("gclid");
|
|
261
|
+
expect(calls[0]).not.toHaveProperty("srsltid");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// The point of the strip: `createCachedLoader`'s default keyFn is
|
|
265
|
+
// JSON.stringify(props), so identical props mean a shared cache entry. A
|
|
266
|
+
// campaign tail used to mint a fresh one on every paid landing.
|
|
267
|
+
it("gives a paid-traffic landing the same props as the clean URL", async () => {
|
|
268
|
+
const calls: Array<Record<string, unknown>> = [];
|
|
269
|
+
registerCommerceLoader(KEY, async (props: Record<string, unknown>) => {
|
|
270
|
+
calls.push({ ...props });
|
|
271
|
+
return null;
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const at = (url: string) =>
|
|
275
|
+
resolveValue({ __resolveType: KEY, slug: "sabonete" }, undefined, {
|
|
276
|
+
url,
|
|
277
|
+
path: "/produto/sabonete/p",
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
await at("https://store.com/produto/sabonete/p");
|
|
281
|
+
await at("https://store.com/produto/sabonete/p?utm_source=google&gclid=abc&fbclid=d");
|
|
282
|
+
|
|
283
|
+
expect(JSON.stringify(calls[1])).toBe(JSON.stringify(calls[0]));
|
|
284
|
+
});
|
|
285
|
+
|
|
242
286
|
it("does NOT override a CMS-configured prop with a URL param of the same name", async () => {
|
|
243
287
|
const calls: Array<Record<string, unknown>> = [];
|
|
244
288
|
registerCommerceLoader(KEY, async (props: Record<string, unknown>) => {
|
package/src/cms/resolve.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { stickyDecide } from "../sdk/experiments";
|
|
|
5
5
|
import { parseSegmentCookie, SEGMENT_COOKIE, type StoredFlag, trafficToPct } from "../sdk/flags";
|
|
6
6
|
import { withInflightTimeout } from "../sdk/inflightTimeout";
|
|
7
7
|
import { normalizeUrlsInObject } from "../sdk/normalizeUrls";
|
|
8
|
+
import { stripTrackingParams } from "../sdk/urlUtils";
|
|
8
9
|
import { findPageByPath, loadBlocks } from "./loader";
|
|
9
10
|
import { getOnBeforeResolveProps, getSection, registerOnBeforeResolveProps } from "./registry";
|
|
10
11
|
import {
|
|
@@ -956,21 +957,35 @@ async function internalResolve(value: unknown, rctx: ResolveContext): Promise<un
|
|
|
956
957
|
resolvedProps.__pagePath = rctx.matcherCtx.path;
|
|
957
958
|
}
|
|
958
959
|
if (rctx.matcherCtx.url) {
|
|
959
|
-
|
|
960
|
+
// Strip tracking params before anything here reaches props.
|
|
961
|
+
//
|
|
962
|
+
// The comment this replaces claimed the enrichment was "safe re: cache
|
|
963
|
+
// fragmentation" because commerce loaders run without a framework-level
|
|
964
|
+
// cache. That was wrong — `getCommerceLoader()` returns the
|
|
965
|
+
// `createCachedLoader`-wrapped functions, whose default keyFn hashes
|
|
966
|
+
// exactly these props — so a `?utm_source`/`gclid`/`srsltid` minted a
|
|
967
|
+
// fresh cache entry and made every paid-traffic landing a permanent cold
|
|
968
|
+
// miss. Measured on a production storefront: 0.2–1.5% hit rate on the
|
|
969
|
+
// default keyFn vs 73.5% on a loader that hand-rolled a key excluding it.
|
|
970
|
+
//
|
|
971
|
+
// Stripping here rather than in the keyFn covers `__pageUrl` and the
|
|
972
|
+
// param spread below in one place, and matches how the edge cache key is
|
|
973
|
+
// already normalized in workerEntry. No loader reads tracking params.
|
|
974
|
+
//
|
|
975
|
+
// Deliberately does NOT drop `__pageUrl`/`__pagePath` themselves: on a
|
|
976
|
+
// PDP the path IS the product identity (the CMS block leaves `slug`
|
|
977
|
+
// null) and on a PLP the query carries the facets. Dropping them would
|
|
978
|
+
// merge distinct results onto one entry and serve wrong content.
|
|
979
|
+
const pageUrl = stripTrackingParams(rctx.matcherCtx.url);
|
|
980
|
+
resolvedProps.__pageUrl = pageUrl;
|
|
960
981
|
// Auto-inject URL search params as top-level props so loaders that
|
|
961
982
|
// expect `props.skuId` / `props.q` / `props.page` (the apps-start
|
|
962
983
|
// canonical shape) get them populated on direct entry (Google
|
|
963
984
|
// Shopping deep links, paid ads, email campaigns). Existing values
|
|
964
985
|
// from the CMS block win — URL params are a fallback, not an
|
|
965
986
|
// override.
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
// path without a framework-level cache (the section/page cache
|
|
969
|
-
// layer hashes section.props BEFORE this enrichment in
|
|
970
|
-
// sectionLoaders.ts), so adding query params here does not
|
|
971
|
-
// fragment any cache key.
|
|
972
|
-
if (URL.canParse(rctx.matcherCtx.url)) {
|
|
973
|
-
const url = new URL(rctx.matcherCtx.url);
|
|
987
|
+
if (URL.canParse(pageUrl)) {
|
|
988
|
+
const url = new URL(pageUrl);
|
|
974
989
|
for (const [k, v] of url.searchParams.entries()) {
|
|
975
990
|
if (resolvedProps[k] !== undefined) continue;
|
|
976
991
|
// `page` is skipped on purpose (#391): loaders that read `page`
|
|
@@ -994,7 +1009,7 @@ async function internalResolve(value: unknown, rctx: ResolveContext): Promise<un
|
|
|
994
1009
|
// upstream is wrong — surface it so the caller can fix it.
|
|
995
1010
|
console.warn(
|
|
996
1011
|
`[CMS] malformed matcherCtx.url for "${resolveType}"; ` +
|
|
997
|
-
`skipping query-param injection: ${
|
|
1012
|
+
`skipping query-param injection: ${pageUrl}`,
|
|
998
1013
|
);
|
|
999
1014
|
}
|
|
1000
1015
|
}
|