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 { DocumentProps } from './utils'
type DocumentContext = {
readonly _documentProps: DocumentProps
readonly _devOnlyInvalidateCacheQueryString: string
}
export const DocumentContext = React.createContext<DocumentContext>(null as any)
export const DocumentContext = React.createContext<DocumentProps>(null as any)
if (process.env.NODE_ENV !== 'production') {
DocumentContext.displayName = 'DocumentContext'
......
......@@ -178,6 +178,7 @@ export type DocumentProps = DocumentInitialProps & {
canonicalBase: string
headTags: any[]
unstable_runtimeJS?: false
devOnlyCacheBusterQueryString: string
}
/**
......
......@@ -147,6 +147,7 @@ export type RenderOptsPartial = {
unstable_runtimeJS?: false
optimizeFonts: boolean
fontManifest?: FontManifest
devOnlyCacheBusterQueryString?: string
}
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
......@@ -183,6 +184,7 @@ function renderDocument(
gip,
appGip,
unstable_runtimeJS,
devOnlyCacheBusterQueryString,
}: RenderOpts & {
props: any
docProps: DocumentInitialProps
......@@ -203,6 +205,7 @@ function renderDocument(
customServer?: boolean
gip?: boolean
appGip?: boolean
devOnlyCacheBusterQueryString: string
}
): string {
return (
......@@ -241,6 +244,7 @@ function renderDocument(
assetPrefix,
headTags,
unstable_runtimeJS,
devOnlyCacheBusterQueryString,
...docProps,
})}
</AmpStateContext.Provider>
......@@ -264,6 +268,13 @@ export async function renderToHTML(
query: ParsedUrlQuery,
renderOpts: RenderOpts
): 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 {
err,
dev = false,
......@@ -283,6 +294,7 @@ export async function renderToHTML(
params,
previewProps,
basePath,
devOnlyCacheBusterQueryString,
} = renderOpts
const getFontDefinition = (url: string): string => {
......@@ -776,6 +788,7 @@ export async function renderToHTML(
gssp: !!getServerSideProps ? true : undefined,
gip: hasPageGetInitialProps ? true : undefined,
appGip: !defaultAppGetInitialProps ? true : undefined,
devOnlyCacheBusterQueryString,
})
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