Repository navigation
fix: narrow the router error before reading its fields - #57
Merged
Merged
Conversation
@tanstack/router-core 1.171.28 types the error passed to route error
components as unknown (ErrorBoundaryTypes defaults to { error: unknown }),
since anything can be thrown. Reading error.message and error.stack stops
typechecking once the router resolves to that version.
Read message and stack only from an actual Error, and stringify anything
else, so the structured log keeps its shape either way.
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.
Summary
@tanstack/router-core1.171.28 changed the type of the error passed to route error components fromErrortounknown. The newErrorBoundaryTypesinterface defaults to{ error: unknown }, since JavaScript can throw anything. The error boundary readerror.messageanderror.stackdirectly, which no longer typechecks.It now reads
messageandstackonly from an actualError, and stringifies anything else, so the structured log keeps its shape either way. The fix compiles on both the old and new router types.Why not augment
ErrorBoundaryTypesto sayerror: Error? That would only restore the old assumption. If something throws a non-Error (throw undefined), the error boundary itself would crash reading.message.Why now
Once Dependabot's next minor/patch group bumps the router past 1.171.28, the typecheck fails on exactly this line. Fixing it now keeps that group from going red.
Verification