fix: report a clear error when a fs-routes page module is marked "use client" - #175
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.collectStaticPathsnow detects the client reference and reports which file to fix, and the othertree.tserrors name the file as well.Changes
tree.ts: detect a client reference via$$typeof === Symbol.for("react.client.reference")next to the existingtypeofguard, and include the source file in the error messages when the tree node carries one.types.ts: add optionalfilePathtoFsRouteTreeNodeso 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 exportinggenerateStaticParamsmust be a Server Component, with the split-and-re-export pattern.The new error:
The two existing
tree.tserrors gain the file name when it is known:filePathis 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:buildRoutesrecordsfilePathon page and layout nodes.Ran
vitest run(120 tests),tsc --noEmit,oxlint,prettier --check, and the package build locally; all pass.