Skip to content

fix: report a clear error when a fs-routes page module is marked "use client" - #175

Merged
uhyo merged 1 commit into
uhyo:masterfrom
k35o:fix-issue-173
Aug 26, 2026
Merged

fix: report a clear error when a fs-routes page module is marked "use client"#175
uhyo merged 1 commit into
uhyo:masterfrom
k35o:fix-issue-173

Conversation

@k35o

@k35o k35o commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Closes #173

Summary

A page module marked "use client" used to fail the build with an error thrown from inside the RSC runtime, with no frame pointing at a source file. collectStaticPaths now detects the client reference and reports which file to fix, and the other tree.ts errors name the file as well.

Changes

  • tree.ts: detect a client reference via $$typeof === Symbol.for("react.client.reference") next to the existing typeof guard, and include the source file in the error messages when the tree node carries one.
  • types.ts: add optional filePath to FsRouteTreeNode so adapters can pass the source file through for diagnostics.
  • nextAdapter.ts: record each page and layout file on the emitted tree nodes.
  • FileSystemRouting.mdx: document that a page module exporting generateStaticParams must be a Server Component, with the split-and-re-export pattern.

The new error:

Dynamic route "/blog/:slug" ("blog/[slug]/page.tsx") exports generateStaticParams()
from a module marked "use client". generateStaticParams() runs on the server at build
time, so a page module cannot be a Client Component. Move the component body into a
separate "use client" module and re-export it from the page:
export { default } from "./_page";

The two existing tree.ts errors gain the file name when it is known:

- Dynamic route "/blog/:slug" has no generateStaticParams() export. ...
+ Dynamic route "/blog/:slug" ("blog/[slug]/page.tsx") has no generateStaticParams() export. ...

- generateStaticParams() for "/blog/:slug" is missing a value for param "slug".
+ generateStaticParams() for "/blog/:slug" ("blog/[slug]/page.tsx") is missing a value for param "slug".

filePath is optional, so hand-built trees and custom adapters that do not set it keep the previous messages.

Tests

  • tree.test.ts: the client-reference error, the file name in the two existing errors, and that a client component page on a static route stays allowed.
  • nextAdapter.test.ts: buildRoutes records filePath on page and layout nodes.

Ran vitest run (120 tests), tsc --noEmit, oxlint, prettier --check, and the package build locally; all pass.

@uhyo uhyo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!! 😃🙏

@uhyo
uhyo merged commit b1aab2b into uhyo:master Aug 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs-routes: report a clear error when a page module is marked "use client"

2 participants