-
-
Notifications
You must be signed in to change notification settings - Fork 333
fix(docs): keep notFound inside route boundaries #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Varkoff
wants to merge
4
commits into
TanStack:main
Choose a base branch
from
Varkoff:fix/docs-notfound-server-boundary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| type DocsNotFoundError = Error & { | ||
| data: { message: string } | ||
| isDocsNotFound: true | ||
| } | ||
|
|
||
| export function createDocsNotFoundError(message = 'No doc was found here!') { | ||
| const error = new Error(message) as DocsNotFoundError | ||
|
|
||
| error.name = 'DocsNotFoundError' | ||
| error.data = { message } | ||
| error.isDocsNotFound = true | ||
|
|
||
| return error | ||
| } | ||
|
|
||
| export function isDocsNotFoundError( | ||
| error: unknown, | ||
| ): error is DocsNotFoundError { | ||
| return ( | ||
| typeof error === 'object' && | ||
| error !== null && | ||
| 'isDocsNotFound' in error && | ||
| error.isDocsNotFound === true | ||
| ) | ||
| } | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
TanStack Start createServerFn thrown error serialization custom properties preserved client💡 Result:
In TanStack Start, errors thrown inside a createServerFn handler are sent back to the client only after being serialized (TanStack uses JSON/seroval-style serialization). This means any non-JSON-serializable data on the thrown value (e.g., Error objects via JSON.stringify, or custom properties that don’t serialize) cannot be preserved as-is on the client. 1) Why “serialization/custom properties preserved client” fails - TanStack explicitly serializes the error to return it to the client. The server-function handler catches the thrown value and JSON.stringify’s the serialized form of the error before returning it in the response body. - As a result, custom properties that aren’t representable by the serializer (and plain Error instances) will be lost or break serialization instead of being preserved. 2) What you can do - Throw Error instances with only JSON-compatible fields (message, name), or construct a plain object error payload yourself and throw/return something that is known-serializable. - Avoid returning/throwing types that include unknown or other non-serializable values; TanStack validates serializability and will error if the return type includes fields like unknown (example shown in a createServerFn issue). - If you need to keep extra error fields, ensure they are serializable primitives/objects (and not instances with methods/prototypes like Error, Response, etc.). 3) Source-backed notes from TanStack - TanStack documents that “Errors are serialized to the client” for server functions. - TanStack Start issue reports that “server functions can’t serialize error objects” because JSON.stringify can’t serialize Error objects (originally). A later comment indicates it was likely fixed, but the core constraint remains: serialization rules apply. - The server runtime code shows the catch path JSON.stringify’ing a cross-JSON serialization of the thrown error. If you paste your exact error shape (what you throw, e.g., throw new Error(...) vs throw {message, ...custom} vs throw someObject) and your expected client-side access (e.g., error.customProp), I can tell you the safest way to structure it for TanStack Start’s serializer.
Citations:
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 15260
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 92
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 92
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 92
🏁 Script executed:
# Read the docs-errors.ts file cat -n src/utils/docs-errors.tsRepository: TanStack/tanstack.com
Length of output: 800
🏁 Script executed:
# Read docs.functions.ts to see how errors are thrown cat -n src/utils/docs.functions.tsRepository: TanStack/tanstack.com
Length of output: 11462
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 3477
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 4512
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 235
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 92
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 167
🏁 Script executed:
Repository: TanStack/tanstack.com
Length of output: 3207
Add fallback structural check for serialized
isDocsNotFoundproperty.TanStack Start serializes errors across the server-function boundary, and custom Error properties don't survive this serialization. The route handlers in
src/routes/$libraryId/$version.docs.$.tsxand.framework.$framework.$.tsxalready handle this for Router errors with the fallback'isNotFound' in errorcheck (lines 42 and 45), but lack an equivalent fallback forisDocsNotFound.Update the error handling in both routes to include:
alongside the existing structural checks. This ensures that
createDocsNotFoundError()thrown fromfetchDocs,fetchFile, andfetchRepoDirectoryContentswill be properly detected on the client after serialization, and the redirect/notFound()fallback logic will trigger correctly for client-side navigation into non-existent docs pages.🤖 Prompt for AI Agents