Skip to content

Commit 91e5b6b

Browse files
devjiwonchoistyfle
andauthored
Backport "fix: add ?dpl to fonts in /_next/static/media (#82384)" (#82421)
Backports #82384 Co-authored-by: Steven <steven@ceriously.com>
1 parent f1629d9 commit 91e5b6b

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

packages/next/src/pages/_document.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ function getAmpPath(ampPath: string, asPath: string): string {
363363
function getNextFontLinkTags(
364364
nextFontManifest: DeepReadonly<NextFontManifest> | undefined,
365365
dangerousAsPath: string,
366-
assetPrefix: string = ''
366+
assetPrefix: string = '',
367+
assetQueryString: string = ''
367368
) {
368369
if (!nextFontManifest) {
369370
return {
@@ -403,7 +404,7 @@ function getNextFontLinkTags(
403404
<link
404405
key={fontFile}
405406
rel="preload"
406-
href={`${assetPrefix}/_next/${encodeURIPath(fontFile)}`}
407+
href={`${assetPrefix}/_next/${encodeURIPath(fontFile)}${assetQueryString}`}
407408
as="font"
408409
type={`font/${ext}`}
409410
crossOrigin="anonymous"
@@ -765,7 +766,8 @@ export class Head extends React.Component<HeadProps> {
765766
const nextFontLinkTags = getNextFontLinkTags(
766767
nextFontManifest,
767768
dangerousAsPath,
768-
assetPrefix
769+
assetPrefix,
770+
this.context.assetQueryString
769771
)
770772

771773
const tracingMetadata = getTracedMetadata(

packages/next/src/server/app-render/get-layer-assets.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function getLayerAssets({
4646
const fontFilename = preloadedFontFiles[i]
4747
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFilename)![1]
4848
const type = `font/${ext}`
49-
const href = `${ctx.assetPrefix}/_next/${encodeURIPath(fontFilename)}`
49+
const href = `${ctx.assetPrefix}/_next/${encodeURIPath(fontFilename)}${getAssetQueryString(ctx, false)}`
5050

5151
preloadCallbacks.push(() => {
5252
ctx.componentMod.preloadFont(

test/production/deployment-id-handling/deployment-id-cookie-handling.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ describe('deployment-id-handling disabled', () => {
4545

4646
for (const link of links) {
4747
if (link.attribs.href) {
48-
if (link.attribs.as === 'font') {
49-
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
50-
} else {
51-
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
52-
}
48+
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
5349
}
5450
}
5551

test/production/deployment-id-handling/deployment-id-handling.test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ describe.each(['NEXT_DEPLOYMENT_ID', 'CUSTOM_DEPLOYMENT_ID'])(
3939

4040
for (const link of links) {
4141
if (link.attribs.href && link.attribs.rel !== 'expect') {
42-
if (link.attribs.as === 'font') {
43-
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
44-
} else {
45-
expect(link.attribs.href).toContain('dpl=' + deploymentId)
46-
}
42+
expect(link.attribs.href).toContain('dpl=' + deploymentId)
4743
}
4844
}
4945

@@ -173,11 +169,7 @@ describe('deployment-id-handling disabled', () => {
173169

174170
for (const link of links) {
175171
if (link.attribs.href) {
176-
if (link.attribs.as === 'font') {
177-
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
178-
} else {
179-
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
180-
}
172+
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
181173
}
182174
}
183175

0 commit comments

Comments
 (0)