Fix Tanstack Start Context Corruption and stop loaders from re-running. #4414
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.
Description
This PR fixes two issues in the Tanstack Start Plugin: Currently, on the initial (server-side) rendered load, the default router context is overwritten with Clerk's initial state. This was problematic for our app because we provide the tRPC client via the default router context. Since it was overwritten on the second run, all loaders would fail. It also doesn’t seem necessary to call
router.load()
, since Tanstack Start will do that anyway, having that in here, was causing all loaders to run twice.To test this, you can use my minimal reproduction: https://github.com/phibr0/clerk-tanstack-start-repro (based on the Example)
.env
file (VITE_CLERK_PUBLISHABLE_KEY
,CLERK_SECRET_KEY
).pnpm install
.pnpm dev
.The context is logged once, and the property
THIS_IS_DEFINED_IN_ROOT_ROUTE
exists.patchedDependencies
in thepackage.json
.pnpm install && pnpm dev
.THIS_IS_DEFINED_IN_ROOT_ROUTE
property is missing.(This is the current behavior.)
Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change