Commit 97a55867 authored by Zack Tanner's avatar Zack Tanner

router restore should take priority over pending actions (#64449)

Since the router processes events sequentially, we special case
`ACTION_NAVIGATE` events to "discard" a pending server action so that it
can process the navigation with higher priority. We should apply this
same logic to `ACTION_RESTORE` events (e.g. `router.back()`) for the
same reason.

Fixes #64432


Closes NEXT-3098
parent bb126178
...@@ -155,8 +155,11 @@ function dispatchAction( ...@@ -155,8 +155,11 @@ function dispatchAction(
action: newAction, action: newAction,
setState, setState,
}) })
} else if (payload.type === ACTION_NAVIGATE) { } else if (
// Navigations take priority over any pending actions. payload.type === ACTION_NAVIGATE ||
payload.type === ACTION_RESTORE
) {
// Navigations (including back/forward) take priority over any pending actions.
// Mark the pending action as discarded (so the state is never applied) and start the navigation action immediately. // Mark the pending action as discarded (so the state is never applied) and start the navigation action immediately.
actionQueue.pending.discarded = true actionQueue.pending.discarded = true
......
...@@ -337,6 +337,19 @@ createNextDescribe( ...@@ -337,6 +337,19 @@ createNextDescribe(
await check(() => browser.url(), `${next.url}/client`, true, 2) await check(() => browser.url(), `${next.url}/client`, true, 2)
}) })
it('should not block router.back() while a server action is in flight', async () => {
let browser = await next.browser('/')
// click /client link to add a history entry
await browser.elementByCss("[href='/client']").click()
await browser.elementByCss('#slow-inc').click()
await browser.back()
// intentionally bailing after 2 retries so we don't retry to the point where the async function resolves
await check(() => browser.url(), `${next.url}/`, true, 2)
})
it('should trigger a refresh for a server action that gets discarded due to a navigation', async () => { it('should trigger a refresh for a server action that gets discarded due to a navigation', async () => {
let browser = await next.browser('/client') let browser = await next.browser('/client')
const initialRandomNumber = await browser const initialRandomNumber = await browser
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment