fix(client): remove useNavigate from AuthKitProvider to avoid SSR warning#59
Open
fix(client): remove useNavigate from AuthKitProvider to avoid SSR warning#59
Conversation
…ning AuthKitProvider is rendered as a Wrap component before RouterProvider context exists. Calling useNavigate() unconditionally during render triggered "useRouter must be used inside a <RouterProvider>" warnings. The navigate function was only used as a fallback in handleSignOut when no sign-out URL was returned. Replace it with window.location.href, which is appropriate for post-sign-out redirects (full page reload is desirable after session termination). Fixes #57
nicknisi
commented
Mar 15, 2026
Member
Author
nicknisi
left a comment
There was a problem hiding this comment.
Reviewer note (info): @tanstack/react-router remains in peerDependencies even though the client bundle no longer imports it. This is correct -- server files in src/server/ still use redirect from @tanstack/react-router. No action needed.
Contributor
Greptile SummaryRemoves the unconditional
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User clicks Sign Out] --> B[handleSignOut called]
B --> C[getSignOutUrl via server fn]
C --> D{result.url returned?}
D -->|Yes| E["window.location.href = result.url<br/>(redirect to WorkOS logout)"]
D -->|No session| F["window.location.href = returnTo<br/>(was: navigate via TanStack Router)"]
E --> G[Session terminated at WorkOS]
F --> H[Full page navigation to returnTo]
Last reviewed commit: c3bf51c |
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
AuthKitProvidercalleduseNavigate()unconditionally at the top of the component body. During SSR with TanStack Start, theWrapcomponent renders beforeRouterProvidercontext is established, causing repeateduseRouter must be used inside a <RouterProvider>console warnings.This PR removes
useNavigateentirely fromAuthKitProvider. ThehandleSignOutfallback navigation now useswindow.location.hrefassignment instead of TanStack Router'snavigate(), which is safe since sign-out is always a user-triggered client-side action.Changes
src/client/AuthKitProvider.tsx: RemoveduseNavigateimport and hook call. Replacednavigate({ to: returnTo })withwindow.location.href = returnToin thehandleSignOutfallback path.src/client/AuthKitProvider.spec.tsx: Removed global@tanstack/react-routermock. Added regression test that rendersAuthKitProviderwithoutRouterProvidercontext (would throw ifuseNavigate()were still called unconditionally). Updated sign-out tests to verifywindow.location.hrefassignment.Closes #57
What was tested
Automated (176 tests pass):
AuthKitProvider.spec.tsxtests pass, including the new regression test"renders without router context (no useNavigate SSR warning)"pnpm buildsucceeds with no type errorsuseNavigatereferences remain in source or builtdist/client/output@tanstack/react-routerimports indist/client/outputManual (Playwright E2E):
localhost:3000useRouter must be used inside a <RouterProvider>warning observedManual reproduction steps
To reproduce the bug on
main:mainand runpnpm install && pnpm buildcd example && pnpm devhttp://localhost:3000in a browser with DevTools console openuseRouter must be used inside a <RouterProvider>warnings in the console during SSR/hydrationTo verify the fix on this branch:
fix/issue-57and runpnpm install && pnpm buildcd example && pnpm devhttp://localhost:3000in a browser with DevTools console openuseRouterwarnings in the consoleVerification
Follow-ups
@tanstack/react-routerremains inpeerDependencieseven though the client bundle no longer imports it. This is correct since server files (src/server/) still useredirectfrom that package. No action needed.