Unverified Commit 91e5b6b8 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Backport "fix: add `?dpl` to fonts in `/_next/static/media` (#82384)" (#82421)

Backports #82384
Co-authored-by: 's avatarSteven <steven@ceriously.com>
parent f1629d93
...@@ -363,7 +363,8 @@ function getAmpPath(ampPath: string, asPath: string): string { ...@@ -363,7 +363,8 @@ function getAmpPath(ampPath: string, asPath: string): string {
function getNextFontLinkTags( function getNextFontLinkTags(
nextFontManifest: DeepReadonly<NextFontManifest> | undefined, nextFontManifest: DeepReadonly<NextFontManifest> | undefined,
dangerousAsPath: string, dangerousAsPath: string,
assetPrefix: string = '' assetPrefix: string = '',
assetQueryString: string = ''
) { ) {
if (!nextFontManifest) { if (!nextFontManifest) {
return { return {
...@@ -403,7 +404,7 @@ function getNextFontLinkTags( ...@@ -403,7 +404,7 @@ function getNextFontLinkTags(
<link <link
key={fontFile} key={fontFile}
rel="preload" rel="preload"
href={`${assetPrefix}/_next/${encodeURIPath(fontFile)}`} href={`${assetPrefix}/_next/${encodeURIPath(fontFile)}${assetQueryString}`}
as="font" as="font"
type={`font/${ext}`} type={`font/${ext}`}
crossOrigin="anonymous" crossOrigin="anonymous"
...@@ -765,7 +766,8 @@ export class Head extends React.Component<HeadProps> { ...@@ -765,7 +766,8 @@ export class Head extends React.Component<HeadProps> {
const nextFontLinkTags = getNextFontLinkTags( const nextFontLinkTags = getNextFontLinkTags(
nextFontManifest, nextFontManifest,
dangerousAsPath, dangerousAsPath,
assetPrefix assetPrefix,
this.context.assetQueryString
) )
const tracingMetadata = getTracedMetadata( const tracingMetadata = getTracedMetadata(
......
...@@ -46,7 +46,7 @@ export function getLayerAssets({ ...@@ -46,7 +46,7 @@ export function getLayerAssets({
const fontFilename = preloadedFontFiles[i] const fontFilename = preloadedFontFiles[i]
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFilename)![1] const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFilename)![1]
const type = `font/${ext}` const type = `font/${ext}`
const href = `${ctx.assetPrefix}/_next/${encodeURIPath(fontFilename)}` const href = `${ctx.assetPrefix}/_next/${encodeURIPath(fontFilename)}${getAssetQueryString(ctx, false)}`
preloadCallbacks.push(() => { preloadCallbacks.push(() => {
ctx.componentMod.preloadFont( ctx.componentMod.preloadFont(
......
...@@ -45,11 +45,7 @@ describe('deployment-id-handling disabled', () => { ...@@ -45,11 +45,7 @@ describe('deployment-id-handling disabled', () => {
for (const link of links) { for (const link of links) {
if (link.attribs.href) { if (link.attribs.href) {
if (link.attribs.as === 'font') {
expect(link.attribs.href).not.toContain('dpl=' + deploymentId) expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
} else {
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
}
} }
} }
......
...@@ -39,13 +39,9 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])( ...@@ -39,13 +39,9 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])(
for (const link of links) { for (const link of links) {
if (link.attribs.href && link.attribs.rel !== 'expect') { if (link.attribs.href && link.attribs.rel !== 'expect') {
if (link.attribs.as === 'font') {
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
} else {
expect(link.attribs.href).toContain('dpl=' + deploymentId) expect(link.attribs.href).toContain('dpl=' + deploymentId)
} }
} }
}
const browser = await next.browser(urlPath) const browser = await next.browser(urlPath)
const requests = [] const requests = []
...@@ -173,11 +169,7 @@ describe('deployment-id-handling disabled', () => { ...@@ -173,11 +169,7 @@ describe('deployment-id-handling disabled', () => {
for (const link of links) { for (const link of links) {
if (link.attribs.href) { if (link.attribs.href) {
if (link.attribs.as === 'font') {
expect(link.attribs.href).not.toContain('dpl=' + deploymentId) expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
} else {
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
}
} }
} }
......
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