Repository navigation
Description
Summary
A production storefront (farmrio-storefront, migrating Fresh→TanStack Start) had every ?page=N request on a PLP silently render page 1, regardless of N. Root-caused to two independent defects that compound each other. Full investigation writeup: farmrio-storefront migration/LEARNINGS.md, "T25" entry (search for [T25]), fix in farmrio-storefront#16.
Defect 1 — packages/apps-vtex/src/loaders/intelligentSearch/productListingPage.ts
const pageFromUrl = pageUrl?.searchParams.get("page");
const rawPage = props.page ?? (pageFromUrl ? Number(pageFromUrl) - 1 : 0);
const page = Number.isFinite(rawPage) && rawPage >= 0 ? Math.floor(rawPage) : 0;Number.isFinite does not coerce (unlike the global isFinite) — Number.isFinite('3') === false. If props.page ever arrives as a string (see defect 2), this silently falls back to page = 0 instead of throwing or coercing. No warning is logged, so the failure is invisible in normal operation — it took direct /deco/invoke A/B testing plus manual instrumentation to find.
Defect 2 — packages/blocks/src/cms/resolve.ts (commerce-loader branch, ~lines 858–874)
if (URL.canParse(rctx.matcherCtx.url)) {
const url = new URL(rctx.matcherCtx.url);
for (const [k, v] of url.searchParams.entries()) {
if (resolvedProps[k] === undefined) resolvedProps[k] = v;
}
}Every commerce loader (both vtex/* and any site/* loader registered the same way) gets every unset URL search param auto-injected onto its top-level props whenever the CMS block config doesn't set it explicitly — intentionally, so direct-entry deep links (Google Shopping, paid ads, email campaigns) populate props.skuId / props.q for loaders that read those directly. But the injected value is always a raw string straight from URLSearchParams, with:
- no type coercion against the loader's own declared prop types (many loaders declare
page?: number), - no awareness that a loader may ALSO independently parse the same param from
__pageUrlwith a different index base —productListingPage.ts's ownpageFromUrlfallback doesNumber(pageFromUrl) - 1(URL is 1-indexed, internalpageis 0-indexed), but the auto-injectedprops.pagebypasses that conversion entirely since it's treated as already-authoritative.
So even patching defect 1 with a bare Number(props.page) reproduces a second, independent off-by-one (?page=3 renders absolute page 4) — only dropping the auto-injected prop entirely (and trusting the loader's own __pageUrl parsing) is fully correct.
Why this is a framework-level footgun, not a one-off
Any loader with a props.<canonicalName> ?? parseFromUrl() pattern for a numeric canonical prop name (page, count, pageOffset, ...) hits the identical landmine — this isn't specific to page or to the VTEX app. It's silent (no dev-time warning, no type error — additionalProperties: true schemas swallow it), and only manifests as a functional bug in real page renders, never in direct /deco/invoke testing (which never sends this auto-injected string), making it unusually hard to root-cause — this one took extensive multi-layer tracing (edge cache, CMS resolve, section-value memoization) before landing on the actual cause.
Suggested fix (either, or both)
- In
resolve.ts's auto-inject loop, coerce known-numeric conventional prop names (page,count,pageOffset, ...) viaNumber(v)before assignment, OR look up the loader's declared prop schema and coerce per-type. - In
productListingPage.ts(and any similarly-shaped loader), defensively coerceprops.page(Number(props.page)) rather than assuming caller type-correctness, and treat a non-finite coerced value as "absent" (fall through to the__pageUrlparse) instead of hard-defaulting to page 0.
Repro
Any site using cmsRouteConfig + a PLP loader wrapper that spreads unset CMS props into vtexProductListingPage (or writes an equivalent props.page ?? parseFromUrl pattern) with a page field NOT explicitly set in the CMS block config. ?page=2, ?page=3, etc. all render page 1's product set.
Activity
fix(apps-vtex,blocks): PLP pagination stuck on page 1 for ?page=N req…
github-actions commentedon Jul 26, 2026
🎉 This issue has been resolved in version 7.22.0 🎉
The release is available on:
blocks-v7.22.0Your semantic-release bot 📦🚀
docs(migration-skill): farmrio-storefront wave — gotchas #52-#73, lea…
Track framework-fix status per issue via real git history
Add MIGRATION_KNOWN_ISSUES.md: consolidated migration gotcha history (#…
fix(apps-vtex): opt-in — a ?page= below 1 is a listing that does not …