Unverified Commit e8c31902 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Support persisting the dev cache buster (#15827)

Same as #15483 but couldn't push to it

---

Closes #15483
Fixes #15828
parent b87e4989
import React from 'react' import React from 'react'
import { DocumentProps } from './utils' import { DocumentProps } from './utils'
type DocumentContext = { export const DocumentContext = React.createContext<DocumentProps>(null as any)
readonly _documentProps: DocumentProps
readonly _devOnlyInvalidateCacheQueryString: string
}
export const DocumentContext = React.createContext<DocumentContext>(null as any)
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
DocumentContext.displayName = 'DocumentContext' DocumentContext.displayName = 'DocumentContext'
......
...@@ -178,6 +178,7 @@ export type DocumentProps = DocumentInitialProps & { ...@@ -178,6 +178,7 @@ export type DocumentProps = DocumentInitialProps & {
canonicalBase: string canonicalBase: string
headTags: any[] headTags: any[]
unstable_runtimeJS?: false unstable_runtimeJS?: false
devOnlyCacheBusterQueryString: string
} }
/** /**
......
...@@ -147,6 +147,7 @@ export type RenderOptsPartial = { ...@@ -147,6 +147,7 @@ export type RenderOptsPartial = {
unstable_runtimeJS?: false unstable_runtimeJS?: false
optimizeFonts: boolean optimizeFonts: boolean
fontManifest?: FontManifest fontManifest?: FontManifest
devOnlyCacheBusterQueryString?: string
} }
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
...@@ -183,6 +184,7 @@ function renderDocument( ...@@ -183,6 +184,7 @@ function renderDocument(
gip, gip,
appGip, appGip,
unstable_runtimeJS, unstable_runtimeJS,
devOnlyCacheBusterQueryString,
}: RenderOpts & { }: RenderOpts & {
props: any props: any
docProps: DocumentInitialProps docProps: DocumentInitialProps
...@@ -203,6 +205,7 @@ function renderDocument( ...@@ -203,6 +205,7 @@ function renderDocument(
customServer?: boolean customServer?: boolean
gip?: boolean gip?: boolean
appGip?: boolean appGip?: boolean
devOnlyCacheBusterQueryString: string
} }
): string { ): string {
return ( return (
...@@ -241,6 +244,7 @@ function renderDocument( ...@@ -241,6 +244,7 @@ function renderDocument(
assetPrefix, assetPrefix,
headTags, headTags,
unstable_runtimeJS, unstable_runtimeJS,
devOnlyCacheBusterQueryString,
...docProps, ...docProps,
})} })}
</AmpStateContext.Provider> </AmpStateContext.Provider>
...@@ -264,6 +268,13 @@ export async function renderToHTML( ...@@ -264,6 +268,13 @@ export async function renderToHTML(
query: ParsedUrlQuery, query: ParsedUrlQuery,
renderOpts: RenderOpts renderOpts: RenderOpts
): Promise<string | null> { ): Promise<string | null> {
// In dev we invalidate the cache by appending a timestamp to the resource URL.
// This is a workaround to fix https://github.com/vercel/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
renderOpts.devOnlyCacheBusterQueryString = renderOpts.dev
? renderOpts.devOnlyCacheBusterQueryString || `?ts=${Date.now()}`
: ''
const { const {
err, err,
dev = false, dev = false,
...@@ -283,6 +294,7 @@ export async function renderToHTML( ...@@ -283,6 +294,7 @@ export async function renderToHTML(
params, params,
previewProps, previewProps,
basePath, basePath,
devOnlyCacheBusterQueryString,
} = renderOpts } = renderOpts
const getFontDefinition = (url: string): string => { const getFontDefinition = (url: string): string => {
...@@ -776,6 +788,7 @@ export async function renderToHTML( ...@@ -776,6 +788,7 @@ export async function renderToHTML(
gssp: !!getServerSideProps ? true : undefined, gssp: !!getServerSideProps ? true : undefined,
gip: hasPageGetInitialProps ? true : undefined, gip: hasPageGetInitialProps ? true : undefined,
appGip: !defaultAppGetInitialProps ? true : undefined, appGip: !defaultAppGetInitialProps ? true : undefined,
devOnlyCacheBusterQueryString,
}) })
if (inAmpMode && html) { if (inAmpMode && html) {
......
This diff is collapsed.
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