-
Notifications
You must be signed in to change notification settings - Fork 419
fix(tanstack-react-start): Handle serialization issue when doing handshake #6345
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
Merged
nikosdouvlis
merged 8 commits into
main
from
rob/user-2383-tanstack-serialization-response
Jul 18, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0f0a367
chore(tanstack-react-start): Fix serialization issues with handshake
wobsoriano 4ce9edb
chore: add changeset
wobsoriano 4cc7c3d
chore: add getAuth tests
wobsoriano 5bdf2a4
chore: set minimum version to 1.127.0
wobsoriano edee388
Merge branch 'main' into rob/user-2383-tanstack-serialization-response
wobsoriano ce72d49
chore: update changeset
wobsoriano db0666c
chore: reinstall deps
wobsoriano f813e9f
chore: reinstall deps
wobsoriano 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
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,6 @@ | ||
| --- | ||
| '@clerk/tanstack-react-start': minor | ||
| --- | ||
|
|
||
| - Fixes serialization errors during handshake | ||
| - Bump `@tanstack/react-start` and `@tanstack/react-router` peer dependency to 1.127.0 |
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
29 changes: 29 additions & 0 deletions
29
integration/templates/tanstack-react-start/src/routes/user.tsx
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,29 @@ | ||
| import { createFileRoute, redirect } from '@tanstack/react-router'; | ||
| import { createServerFn } from '@tanstack/react-start'; | ||
| import { getAuth } from '@clerk/tanstack-react-start/server'; | ||
| import { getWebRequest } from '@tanstack/react-start/server'; | ||
|
|
||
| const fetchClerkAuth = createServerFn({ method: 'GET' }).handler(async () => { | ||
| const request = getWebRequest(); | ||
| if (!request) throw new Error('No request found'); | ||
|
|
||
| const { userId } = await getAuth(request); | ||
|
|
||
| return { | ||
| userId, | ||
| }; | ||
| }); | ||
|
|
||
| export const Route = createFileRoute('/')({ | ||
| component: Page, | ||
| beforeLoad: async () => await fetchClerkAuth(), | ||
| loader: async ({ context }) => { | ||
| return { userId: context.userId }; | ||
| }, | ||
| }); | ||
|
|
||
| function Page() { | ||
| const state = Route.useLoaderData(); | ||
|
|
||
| return state.userId ? <h1>Welcome! Your ID is {state.userId}!</h1> : <h1>You are not signed in</h1>; | ||
| } | ||
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,11 @@ | ||
| export class ClerkHandshakeRedirect extends Error { | ||
| constructor( | ||
| public status: number, | ||
| public headers: Headers, | ||
| ) { | ||
| super('Clerk handshake redirect required'); | ||
| this.name = 'ClerkHandshakeRedirect'; | ||
| this.status = status; | ||
| this.headers = headers; | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Fix the route configuration logic.
The route configuration has several critical issues:
beforeLoadhook should return data that becomes available in the contextcontext.userIdexists without validationexport const Route = createFileRoute('/')({ component: Page, - beforeLoad: async () => await fetchClerkAuth(), + beforeLoad: async () => { + const authData = await fetchClerkAuth(); + return authData; + }, loader: async ({ context }) => { - return { userId: context.userId }; + return { userId: (context as any).userId || null }; }, });📝 Committable suggestion
🤖 Prompt for AI Agents