From ea4fea78b75a8f343108a276aa2f437167bb0670 Mon Sep 17 00:00:00 2001 From: Yunfei He Date: Sun, 1 Mar 2026 17:04:02 +0800 Subject: [PATCH] test: add failing test for dynamic prerender with getPrerenderPaths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `collectPrerenderPaths()` crashes with `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')` when resolving dynamic pages that export `getPrerenderPaths`. Root cause: `collectPrerenderPaths()` calls `createServer()` which loads the user's vite.config — including `@cloudflare/vite-plugin` with `viteEnvironment: { name: "ssr" }`. This replaces the SSR environment with a `FetchableDevEnvironment` (CloudflareDevEnvironment). When `ssrLoadModule()` is then called, it creates an `SSRCompatModuleRunner` whose transport unconditionally accesses `environment.hot.api.outsideEmitter` — but `FetchableDevEnvironment`'s hot channel has no `api` property, causing the crash. The existing static-pages test only covered: - Static pages (no params) — prerendered via pattern matching, no `ssrLoadModule()` needed - Dynamic pages WITHOUT `getPrerenderPaths` — asserted as NOT prerendered This adds a `posts/[slug]` page that exports `getPrerenderPaths` returning two paths, exercising the `ssrLoadModule()` code path in `collectPrerenderPaths()`. Co-Authored-By: Claude Opus 4.6 --- .../void/test/integration/static-pages.test.ts | 12 ++++++++++++ .../static-pages/pages/posts/[slug].server.ts | 15 +++++++++++++++ playground/static-pages/pages/posts/[slug].vue | 9 +++++++++ 3 files changed, 36 insertions(+) create mode 100644 playground/static-pages/pages/posts/[slug].server.ts create mode 100644 playground/static-pages/pages/posts/[slug].vue diff --git a/packages/void/test/integration/static-pages.test.ts b/packages/void/test/integration/static-pages.test.ts index 9b64db4f0..c37e2e35d 100644 --- a/packages/void/test/integration/static-pages.test.ts +++ b/packages/void/test/integration/static-pages.test.ts @@ -61,6 +61,18 @@ describe("playground/static-pages build (output: static)", () => { expect(html).not.toContain("/@id/"); }); + it("prerenders dynamic pages with getPrerenderPaths", () => { + // posts/[slug] exports getPrerenderPaths returning [{slug:"hello"},{slug:"world"}] + const helloPath = join(DIST, "client/posts/hello.html"); + const worldPath = join(DIST, "client/posts/world.html"); + expect(existsSync(helloPath)).toBe(true); + expect(existsSync(worldPath)).toBe(true); + + const html = readFileSync(helloPath, "utf-8"); + expect(html).toContain('data-testid="post-title"'); + expect(html).toContain("Post hello"); + }); + it("does not prerender dynamic pages without getPrerenderPaths", () => { // items/[id] has no getPrerenderPaths, so it should NOT be prerendered expect(existsSync(join(DIST, "client/items"))).toBe(false); diff --git a/playground/static-pages/pages/posts/[slug].server.ts b/playground/static-pages/pages/posts/[slug].server.ts new file mode 100644 index 000000000..69cc74fc2 --- /dev/null +++ b/playground/static-pages/pages/posts/[slug].server.ts @@ -0,0 +1,15 @@ +import { defineHandler } from "void"; + +export interface Props { + slug: string; +} + +export const prerender = true; + +export function getPrerenderPaths() { + return [{ slug: "hello" }, { slug: "world" }]; +} + +export const loader = defineHandler((c) => { + return { slug: c.req.param("slug") }; +}); diff --git a/playground/static-pages/pages/posts/[slug].vue b/playground/static-pages/pages/posts/[slug].vue new file mode 100644 index 000000000..e547f47fe --- /dev/null +++ b/playground/static-pages/pages/posts/[slug].vue @@ -0,0 +1,9 @@ + + +