Skip to content

Commit

Permalink
ensure mpa navigations to the same URL work after restoring from bfcache
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Mar 11, 2024
1 parent c860a2a commit a9cb95f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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"'
)
})
})

0 comments on commit a9cb95f

Please sign in to comment.