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

ensure mpa navigations to the same URL work after restoring from bfcache #63155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ function Router({
return
}

// Clear the pendingMpaPath value so that a subsequent MPA navigation to the same URL can be triggered.
// This is necessary because if the browser restored from bfcache, the pendingMpaPath would still be set to the value
// of the last MPA navigation.
globalMutable.pendingMpaPath = undefined

dispatch({
type: ACTION_RESTORE,
url: new URL(window.location.href),
Expand Down
10 changes: 10 additions & 0 deletions test/production/bfcache-routing/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,15 @@ describe('bfcache-routing', () => {
// we should be back on the test page with no errors
html = await browser.evalAsync('document.documentElement.innerHTML')
expect(html).toContain('BFCache Test')

// After restoring from bfcache, a subsequent mpa navigation to the same URL should work
// We trigger the click via `evalAsync` because when restoring from bfcache, our internal
// 'waitForElementByCss' method doesn't think the element is attached to the DOM.
await browser.evalAsync(
`document.querySelector('a[href="https://example.vercel.sh"]').click()`
)
await browser.waitForCondition(
'window.location.origin === "https://example.vercel.sh"'
)
})
})