Skip to content
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

Fix Tanstack Start Context Corruption and stop loaders from re-running. #4414

Closed
wants to merge 3 commits into from

Conversation

phibr0
Copy link
Contributor

@phibr0 phibr0 commented Oct 27, 2024

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)

  1. Provide keys in a .env file (VITE_CLERK_PUBLISHABLE_KEY, CLERK_SECRET_KEY).
  2. Run pnpm install.
  3. Run pnpm dev.

Screenshot 2024-10-27 at 12 42 38

The context is logged once, and the property THIS_IS_DEFINED_IN_ROOT_ROUTE exists.

  1. Remove the patch by deleting patchedDependencies in the package.json.
  2. Run pnpm install && pnpm dev.
    • Navigate to http://localhost:3000/.
    • The route context will be logged twice in the server console, and the second time, the THIS_IS_DEFINED_IN_ROOT_ROUTE property is missing.

(This is the current behavior.)

Screenshot 2024-10-27 at 12 49 10

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Oct 27, 2024

🦋 Changeset detected

Latest commit: 8ce5df1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/tanstack-start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@alexcarpenter
Copy link
Member

This is a duplicate of #4345

@alexcarpenter
Copy link
Member

Thanks @phibr0 for the PR! Will be closing in favor of #4345 which was already in progress.

@phibr0
Copy link
Contributor Author

phibr0 commented Oct 28, 2024

No problem! Not sure how I missed that

@kaandok
Copy link

kaandok commented Dec 23, 2024

@alexcarpenter This is still happening since the fix has been reverted in dac21ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants