Skip to content

Commit

Permalink
Update id handling for fonts (#52559)
Browse files Browse the repository at this point in the history
We don't need to apply the ID here as these assets should always be available across deploys. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1689035592272659)
  • Loading branch information
ijjk committed Jul 11, 2023
1 parent 56fcd7a commit fab164d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
15 changes: 3 additions & 12 deletions packages/next/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ function getAmpPath(ampPath: string, asPath: string): string {
function getNextFontLinkTags(
nextFontManifest: NextFontManifest | undefined,
dangerousAsPath: string,
assetPrefix: string = '',
assetQueryString: string = ''
assetPrefix: string = ''
) {
if (!nextFontManifest) {
return {
Expand All @@ -378,11 +377,6 @@ function getNextFontLinkTags(
(appFontsEntry || pageFontsEntry)
)

// we only add if the dpl query is present for fonts
if (!assetQueryString.includes('dpl=')) {
assetQueryString = ''
}

return {
preconnect: preconnectToSelf ? (
<link
Expand All @@ -401,9 +395,7 @@ function getNextFontLinkTags(
<link
key={fontFile}
rel="preload"
href={`${assetPrefix}/_next/${encodeURI(
fontFile
)}${assetQueryString}`}
href={`${assetPrefix}/_next/${encodeURI(fontFile)}`}
as="font"
type={`font/${ext}`}
crossOrigin="anonymous"
Expand Down Expand Up @@ -800,8 +792,7 @@ export class Head extends React.Component<HeadProps> {
const nextFontLinkTags = getNextFontLinkTags(
nextFontManifest,
dangerousAsPath,
assetPrefix,
this.context.assetQueryString
assetPrefix
)

return (
Expand Down
4 changes: 1 addition & 3 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,7 @@ export async function renderToHTMLOrFlight(
const fontFilename = preloadedFontFiles[i]
const ext = /\.(woff|woff2|eot|ttf|otf)$/.exec(fontFilename)![1]
const type = `font/${ext}`
const href = `${assetPrefix}/_next/${fontFilename}${getAssetQueryString(
false
)}`
const href = `${assetPrefix}/_next/${fontFilename}`
ComponentMod.preloadFont(href, type)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ createNextDescribe(

for (const link of links) {
if (link.attribs.href) {
expect(link.attribs.href).toContain('dpl=' + deploymentId)
if (link.attribs.as === 'font') {
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
} else {
expect(link.attribs.href).toContain('dpl=' + deploymentId)
}
}
}

Expand Down

0 comments on commit fab164d

Please sign in to comment.