diff --git a/packages/next/shared/lib/router/router.ts b/packages/next/shared/lib/router/router.ts index c0e6bd190168d..b6d789925cacf 100644 --- a/packages/next/shared/lib/router/router.ts +++ b/packages/next/shared/lib/router/router.ts @@ -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) { diff --git a/test/production/prerender-prefetch/index.test.ts b/test/production/prerender-prefetch/index.test.ts index 9ddd876114279..c15557c794503 100644 --- a/test/production/prerender-prefetch/index.test.ts +++ b/test/production/prerender-prefetch/index.test.ts @@ -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, '/')