Files
James Anderson 617605b925 fix(prerender): support string paths and missing params in getStaticPaths (#1227)
Next.js allows getStaticPaths to return paths as either
Array<{ params }> or Array<string> (see Next.js docs and
.nextjs-ref/packages/next/src/build/static-paths/pages.ts). vinext only
handled the object shape, so a fixture returning string paths crashed
the prerender phase with:

  TypeError: Cannot read properties of undefined (reading 'slug')
    at buildUrlFromParams (packages/vinext/src/build/prerender.ts:311)

This blocked ~213 Next.js deploy-suite tests
(see https://github.com/cloudflare/vinext/actions/runs/25897889733 —
middleware-general index/node-runtime, middleware-rewrites, and
middleware-trailing-slash all gated on this single build crash).

Changes:
- buildUrlFromParams: defensively throw a descriptive error when
  params itself is null/undefined, instead of crashing with a cryptic
  TypeError pointing at a dist line.
- prerenderPages (Pages Router): normalize each paths entry. Strings
  are run through the route pattern matcher to extract params, mirroring
  Next.js _routeMatcher(cleanedEntry). Missing/null params surface as
  per-route error results instead of crashing the whole prerender.
- prerenderApp (App Router): defensively guard each entry from
  generateStaticParams() against missing params with a clear error
  message in the existing try/catch.
- pages-page-data.ts (prod SSR): matchesPagesStaticPath now handles
  string entries via URL comparison and guards undefined params.
- dev-server.ts (dev SSR): same string-path + missing-params handling
  for the dev request path.
- Tests: add tests/fixtures/pages-basic/pages/string-paths/[slug].tsx
  and missing-params/[slug].tsx, with two new vitest cases asserting
  successful prerender and a per-route error result.
2026-05-15 09:34:01 +00:00

27 lines
976 B
TypeScript

import React from "react";
export default function MissingParams() {
return <div>missing-params</div>;
}
// Returns an item with no `params` key. Next.js throws
// "A required parameter (slug) was not provided as a string received undefined"
// (see .nextjs-ref/packages/next/src/build/static-paths/pages.ts around line 169).
// vinext mirrors this by surfacing a per-route error in the prerender result
// rather than crashing the whole prerender phase.
export async function getStaticPaths() {
return {
paths: [
{ params: { slug: "ok" } } as { params: { slug: string } } | { locale: string },
// Force the wrong shape past the type checker — we are testing the
// runtime defensive behavior, not the type system.
{ locale: "en" } as unknown as { params: { slug: string } },
],
fallback: false,
};
}
export async function getStaticProps({ params }: { params: { slug: string } }) {
return { props: { slug: params.slug } };
}