Skip to content

PLP page/pagination props silently pinned to page 1: auto-injected URL params are raw strings, and Number.isFinite doesn't coerce #391

Closed

Description

@hugo-ccabral

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 __pageUrl with a different index base — productListingPage.ts's own pageFromUrl fallback does Number(pageFromUrl) - 1 (URL is 1-indexed, internal page is 0-indexed), but the auto-injected props.page bypasses 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)

  1. In resolve.ts's auto-inject loop, coerce known-numeric conventional prop names (page, count, pageOffset, ...) via Number(v) before assignment, OR look up the loader's declared prop schema and coerce per-type.
  2. In productListingPage.ts (and any similarly-shaped loader), defensively coerce props.page (Number(props.page)) rather than assuming caller type-correctness, and treat a non-finite coerced value as "absent" (fall through to the __pageUrl parse) 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

  1. added a commit that references this issue on Jul 26, 2026
    28757f8
  2. github-actions commented on Jul 26, 2026

    @github-actions

    🎉 This issue has been resolved in version 7.22.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions