You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds unit and integration tests to validate that removing usePathname from useInternalNavFun's effect deps (#7989) doesn't regress the navigation promise flushing behavior originally fixed in #2899.
Context
PR #7989 changed the flush effect deps from [pathname, isPending] to [isPending] to fix cacheComponents: true build failures. The concern raised was: "how did we test this? I think usePathname was added because we were seeing the promise never resolve in some scenarios without it."
Investigation of the original PR #2889/#2899 review comments revealed:
The real fix was moving the promise buffer from useRef to window (surviving ClerkProvider unmount/remount)
usePathname was added as a belt-and-suspenders safety net — the original author stated "I never managed to reproduce a failed setActive because of us not listening to isPending"
usePathname actually introduced a latent bug: same-path navigations would hang because pathname wouldn't change
Full setActive(null) -> navigate(redirectUrl) -> routerPush -> useInternalNavFun -> startTransition chain. If isPending doesn't cycle, signOut() hangs and the test times out.
Protected route redirects after sign out
Cache invalidation + navigation work correctly end-to-end
The E2E tests run against cacheComponents: true (the exact environment where #7989's change matters) and exercise real Next.js routing where isPending behavior differs from mocked unit tests.
Test plan
pnpm vitest run packages/nextjs/src/app-router/client/__tests__/useInternalNavFun.test.tsx passes (14/14 tests, 0 type errors)
CI passes (integration tests run in CI against next.cacheComponents pattern)
Summary by CodeRabbit
Tests
Added integration tests for sign-out behavior and navigation flows.
Added unit tests for internal navigation functionality and promise resolution.
…lution
Add unit and integration tests to validate that removing usePathname
from useInternalNavFun's effect deps (#7989) doesn't regress the
navigation promise flushing behavior originally fixed in #2899.
Unit tests:
- Single navigation promise resolves via isPending alone
- Pre-existing window buffer flushed on mount (ClerkProvider remount)
- Pending promises flushed on unmount (ClerkProvider unmount)
- Internal navigations use history pushState instead of router
Integration tests (cache-components / cacheComponents: true):
- Sign out completes without hanging (exercises full setActive → navigate → routerPush → useInternalNavFun chain)
- Protected route redirects correctly after sign out (validates cache invalidation + navigation)
This pull request adds test coverage for navigation promise handling and sign-out behavior. A changeset file is introduced to document the changes. Two new integration tests verify that sign-out operations complete successfully and that protected routes redirect appropriately after sign-out. Additionally, unit tests are added for the useInternalNavFun hook to cover navigation promise resolution, buffer flushing on component mount and unmount, and internal navigation using window history state management.
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
✅ Passed
The title clearly and specifically describes the main change: adding tests for useInternalNavFun navigation promise resolution, which aligns with the test additions across unit and integration test files.
Docstring Coverage
✅ Passed
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Comment @coderabbitai help to get the list of available commands and usage tips.
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
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
Adds unit and integration tests to validate that removing
usePathnamefromuseInternalNavFun's effect deps (#7989) doesn't regress the navigation promise flushing behavior originally fixed in #2899.Context
PR #7989 changed the flush effect deps from
[pathname, isPending]to[isPending]to fixcacheComponents: truebuild failures. The concern raised was: "how did we test this? I thinkusePathnamewas added because we were seeing the promise never resolve in some scenarios without it."Investigation of the original PR #2889/#2899 review comments revealed:
useReftowindow(surviving ClerkProvider unmount/remount)usePathnamewas added as a belt-and-suspenders safety net — the original author stated "I never managed to reproduce a failed setActive because of us not listening toisPending"usePathnameactually introduced a latent bug: same-path navigations would hang because pathname wouldn't changeUnit tests (
useInternalNavFun.test.tsx)isPending-only mechanism worksnavigationType === 'internal'pathIntegration tests (
cache-components.test.ts)setActive(null)->navigate(redirectUrl)->routerPush->useInternalNavFun->startTransitionchain. IfisPendingdoesn't cycle,signOut()hangs and the test times out.The E2E tests run against
cacheComponents: true(the exact environment where #7989's change matters) and exercise real Next.js routing whereisPendingbehavior differs from mocked unit tests.Test plan
pnpm vitest run packages/nextjs/src/app-router/client/__tests__/useInternalNavFun.test.tsxpasses (14/14 tests, 0 type errors)next.cacheComponentspattern)Summary by CodeRabbit