Implement useRouter bfcacheId semantics#1588
Conversation
commit: |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e66ec5c91c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const segmentCount = getVisibleTreePathSegments(parsed.treePath).length; | ||
| return `${id}@${getPathPrefix(pathname, segmentCount)}`; |
There was a problem hiding this comment.
Handle catch-all segments when deriving bfcache identities
createBfcacheSegmentIdentity() derives layout/slot/template identity from a fixed path-prefix length (getVisibleTreePathSegments(...).length), which treats each dynamic segment as consuming exactly one URL segment. For catch-all routes like [...slug]/[[...slug]], the segment value spans the remaining path, so navigating /docs/a/b → /docs/a/c keeps the same computed prefix (/docs/a) and incorrectly reuses the previous bfcache id. That preserves client state for a segment whose params actually changed, so useRouter().bfcacheId semantics diverge for catch-all layouts/templates/slots.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I’ve updated it accordingly.
|
Important PR bro, I think it’ll get merged when maintainer is online. That said, there are a few improvements to be made. Blocking1.
|
Summary
useRouter().bfcacheIdsemantics for the App Router shim.Feedback addressed
This is a fresh follow-up based on the review feedback from the earlier bfcacheId PR. In particular, this version:
_appRouterByBfcacheIdwith a small LRU cache instead of leaving it unboundedrouter.push()/router.replace()coverage in the E2E fixtureTests
./node_modules/.bin/vp check packages/vinext/src/server/app-history-state.ts packages/vinext/src/server/app-browser-state.ts packages/vinext/src/server/app-browser-visible-commit.ts packages/vinext/src/server/app-browser-navigation-controller.ts packages/vinext/src/server/app-browser-entry.ts packages/vinext/src/server/app-ssr-entry.ts packages/vinext/src/shims/navigation.ts packages/vinext/src/shims/slot.tsx tests/app-browser-entry.test.ts tests/shims.test.ts tests/e2e/app-router/nextjs-compat/use-router-bfcache-id.spec.ts tests/fixtures/app-basic/app/nextjs-compat/use-router-bfcache-id/[group]/[page]/leaf-content.tsx./node_modules/.bin/vp test run tests/shims.test.ts -t "useRouter|bfcache|hash-only"./node_modules/.bin/vp test run tests/app-browser-entry.test.ts -t "bfcache|parallel"PLAYWRIGHT_PROJECT=app-router ./node_modules/.bin/playwright test tests/e2e/app-router/nextjs-compat/use-router-bfcache-id.spec.tsPLAYWRIGHT_PROJECT=app-router ./node_modules/.bin/playwright test tests/e2e/app-router/nextjs-compat/hash-popstate-scroll.spec.ts