mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
617605b925
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.
36 lines
885 B
TypeScript
36 lines
885 B
TypeScript
import React from "react";
|
|
|
|
interface StringPathProps {
|
|
slug: string;
|
|
}
|
|
|
|
export default function StringPath({ slug }: StringPathProps) {
|
|
return (
|
|
<div>
|
|
<h1>String path</h1>
|
|
<p>Slug: {slug}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Next.js allows getStaticPaths to return `paths` as either:
|
|
// - Array<{ params: { ... } }>
|
|
// - Array<string>
|
|
// See https://nextjs.org/docs/pages/api-reference/functions/get-static-paths
|
|
// and .nextjs-ref/packages/next/src/build/static-paths/pages.ts (handles both
|
|
// shapes by running the string path through the route matcher to extract params).
|
|
export async function getStaticPaths() {
|
|
return {
|
|
paths: ["/string-paths/hello-world", "/string-paths/another-one"],
|
|
fallback: false,
|
|
};
|
|
}
|
|
|
|
export async function getStaticProps({ params }: { params: { slug: string } }) {
|
|
return {
|
|
props: {
|
|
slug: params.slug,
|
|
},
|
|
};
|
|
}
|