-
Notifications
You must be signed in to change notification settings - Fork 388
fix(nuxt): Prevent Nuxt route middlewares from seeing intermediate states during navigation #6802
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
Conversation
🦋 Changeset detectedLatest commit: 1e4d628 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughIntroduces a changeset entry for a patch release and updates the Nuxt runtime plugin to defer router navigation by wrapping navigateTo calls in nextTick for both routerPush and routerReplace. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant AuthFlow as Auth Flow
participant Plugin as Nuxt Plugin
participant Middleware
participant Router
User->>AuthFlow: Trigger sign-in/sign-out
AuthFlow->>Plugin: routerPush/routerReplace(to)
note over Plugin: New behavior: schedule navigation on nextTick
Plugin->>Plugin: nextTick(() => navigateTo(to))
Plugin-->>AuthFlow: Promise (from nextTick)
rect rgba(230,245,255,0.5)
note right of Middleware: Middleware sees stable state (no intermediate navigation)
end
Plugin->>Router: navigateTo(to) (on next tick)
Router->>Middleware: Run route middleware
Middleware-->>Router: Continue or redirect
Router-->>User: Final route
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
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.
Actionable comments posted: 2
🧹 Nitpick comments (3)
.changeset/funny-peaches-float.md (1)
1-5
: Changelog is clear; consider noting the mechanism.Add a brief note that navigation is deferred with Vue.nextTick() so middleware won’t observe transient auth states. Helps downstream maintainers understand the fix at a glance.
Fixed an issue where Nuxt route middleware saw intermediate states during navigation, causing unwanted redirects during sign-in/sign-out flows. +Navigation is now deferred to the next Vue tick so middleware only runs after auth state settles.
packages/nuxt/src/runtime/plugin.ts (2)
7-9
: Avoid ts-expect-error; import nextTick from vue.Relying on
#imports
here forces a suppression and weakens type safety. Importing fromvue
works in Nuxt runtime code and removes the need for the directive.-// @ts-expect-error: Handled by Nuxt. -import { nextTick } from '#imports'; +import { nextTick } from 'vue';
31-40
: Document why the deferral exists.Add a short JSDoc explaining the auth-state race this mitigates and that SSR is not deferred.
- routerPush: (to: string): ReturnType<typeof navigateTo> => { + /** Defer client navigation by one tick so route middleware runs after auth state settles (prevents flicker/loops). + * On SSR, navigate immediately to preserve redirect semantics. + */ + routerPush: (to: string): ReturnType<typeof navigateTo> => { @@ - routerReplace: (to: string): ReturnType<typeof navigateTo> => { + /** Same as routerPush but with { replace: true }. */ + routerReplace: (to: string): ReturnType<typeof navigateTo> => {
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
.changeset/funny-peaches-float.md
(1 hunks)packages/nuxt/src/runtime/plugin.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/funny-peaches-float.md
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nuxt/src/runtime/plugin.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nuxt/src/runtime/plugin.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nuxt/src/runtime/plugin.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nuxt/src/runtime/plugin.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nuxt/src/runtime/plugin.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nuxt/src/runtime/plugin.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Static analysis
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/nuxt/src/runtime/plugin.ts (1)
31-40
: No awaiting callers found — change is safeRepo search shows occurrences only in packages/nuxt/src/runtime/plugin.ts (this change), packages/react/src/contexts/tests/ClerkProvider.test.tsx (mocked as () => {}), and packages/astro/src/integration/create-integration.ts (passes navigate); no
await routerPush
/await routerReplace
usages or @clerk/vue callers found.
Description
During auth transitions (sign-in and sign-out), Vue shows intermediate state changes causing UI flicker and confusing redirects. For example (notice how it goes from
/sign-in
->/dashboard
->sign-in
->/dashboard
):Screen.Recording.2025-09-17.at.6.43.00.PM.mov
What's happening above:
fallbackRedirectUrl
orforceRedirectUrl
useAuth().userId.value
user -> null -> undefined -> user
)fallbackRedirectUrl
orforceRedirectUrl
By adding
nextTick()
, it's ensuring that navigation happens after the state is fully settled, preventing route middleware from seeing intermediate states.Fixed demo, from
/sign-in
->/dashboard
Screen.Recording.2025-09-17.at.6.44.54.PM.mov
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Chores