Unverified Commit eb424042 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure skipClientCache is honored for router.push (#40932)

Fixes: https://github.com/vercel/next.js/issues/40927

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
parent 4f70f3af
......@@ -1550,6 +1550,7 @@ export default class Router implements BaseRouter {
locale: nextState.locale,
isPreview: nextState.isPreview,
hasMiddleware: isMiddlewareMatch,
unstable_skipClientCache: options.unstable_skipClientCache,
})
if ('route' in routeInfo && isMiddlewareMatch) {
......
......@@ -135,6 +135,52 @@ describe('Prerender prefetch', () => {
expect(isNaN(newTime)).toBe(false)
})
it('should update cache using router.push with unstable_skipClientCache', async () => {
const browser = await webdriver(next.url, '/')
const timeRes = await fetchViaHTTP(
next.url,
`/_next/data/${next.buildId}/blog/first.json`,
undefined,
{
headers: {
purpose: 'prefetch',
},
}
)
const startTime = (await timeRes.json()).pageProps.now
// ensure stale data is used by default
await browser.elementByCss('#to-blog-first').click()
const outputIndex = next.cliOutput.length
await check(() => browser.elementByCss('#page').text(), 'blog/[slug]')
expect(JSON.parse(await browser.elementByCss('#props').text()).now).toBe(
startTime
)
await browser.back().waitForElementByCss('#to-blog-first')
// trigger revalidation of /blog/first
await check(async () => {
await renderViaHTTP(next.url, '/blog/first')
return next.cliOutput.substring(outputIndex)
}, /revalidating \/blog first/)
// now trigger cache update and navigate again
await browser.eval(
'next.router.push("/blog/first", undefined, { unstable_skipClientCache: true }).finally(() => { window.prefetchDone = "yes" })'
)
await check(() => browser.eval('window.prefetchDone'), 'yes')
await check(() => browser.elementByCss('#page').text(), 'blog/[slug]')
const newTime = JSON.parse(
await browser.elementByCss('#props').text()
).now
expect(newTime).not.toBe(startTime)
expect(isNaN(newTime)).toBe(false)
})
if (optimisticClientCache) {
it('should attempt cache update on link hover/touch start', async () => {
const browser = await webdriver(next.url, '/')
......
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