Unverified Commit e8fcf8b5 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

Add data attributes on @next/font usage (#45296)

Adds `data-next-font` data attribute to the preload tag if added by
`@next/font`.
```js
// Using `size-adjust` fallback font.
<link data-next-font="size-adjust" rel="preload" href="..." as="font" type="font/woff2" crossorigin="anonymous">

// Not using `size-adjust` fallback font.
<link data-next-font="" rel="preload" href="..." as="font" type="font/woff2" crossorigin="anonymous">
```

If no fonts are preloaded, the tag is added on the preconnect tag.

Fixes NEXT-350

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent fb62d7e8
...@@ -155,7 +155,8 @@ const downloadGoogleFonts: FontLoader = async ({ ...@@ -155,7 +155,8 @@ const downloadGoogleFonts: FontLoader = async ({
const selfHostedFileUrl = emitFontFile( const selfHostedFileUrl = emitFontFile(
fontFileBuffer, fontFileBuffer,
ext, ext,
preloadFontFile preloadFontFile,
!!adjustFontFallbackMetrics
) )
return { return {
......
...@@ -75,7 +75,12 @@ const fetchFonts: FontLoader = async ({ ...@@ -75,7 +75,12 @@ const fetchFonts: FontLoader = async ({
src.map(async ({ path, style, weight, ext, format }) => { src.map(async ({ path, style, weight, ext, format }) => {
const resolved = await resolve(path) const resolved = await resolve(path)
const fileBuffer = await promisify(loaderContext.fs.readFile)(resolved) const fileBuffer = await promisify(loaderContext.fs.readFile)(resolved)
const fontUrl = emitFontFile(fileBuffer, ext, preload) const fontUrl = emitFontFile(
fileBuffer,
ext,
preload,
typeof adjustFontFallback === 'undefined' || !!adjustFontFallback
)
let fontMetadata: any let fontMetadata: any
try { try {
......
...@@ -11,7 +11,12 @@ export type FontLoader = (options: { ...@@ -11,7 +11,12 @@ export type FontLoader = (options: {
variableName: string variableName: string
data: any[] data: any[]
config: any config: any
emitFontFile: (content: Buffer, ext: string, preload: boolean) => string emitFontFile: (
content: Buffer,
ext: string,
preload: boolean,
isUsingSizeAdjust?: boolean
) => string
resolve: (src: string) => string resolve: (src: string) => string
isDev: boolean isDev: boolean
isServer: boolean isServer: boolean
......
...@@ -59,12 +59,19 @@ export default async function nextFontLoader(this: any) { ...@@ -59,12 +59,19 @@ export default async function nextFontLoader(this: any) {
}) })
) )
const emitFontFile = (content: Buffer, ext: string, preload: boolean) => { const emitFontFile = (
content: Buffer,
ext: string,
preload: boolean,
isUsingSizeAdjust?: boolean
) => {
const opts = { context: this.rootContext, content } const opts = { context: this.rootContext, content }
const interpolatedName = loaderUtils.interpolateName( const interpolatedName = loaderUtils.interpolateName(
this, this,
// Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded // Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded
`static/media/[hash]${preload ? '.p' : ''}.${ext}`, `static/media/[hash]${isUsingSizeAdjust ? '-s' : ''}${
preload ? '.p' : ''
}.${ext}`,
opts opts
) )
const outputPath = `${assetPrefix}/_next/${interpolatedName}` const outputPath = `${assetPrefix}/_next/${interpolatedName}`
......
...@@ -9,6 +9,8 @@ export type FontLoaderManifest = { ...@@ -9,6 +9,8 @@ export type FontLoaderManifest = {
app: { app: {
[moduleRequest: string]: string[] [moduleRequest: string]: string[]
} }
appUsingSizeAdjust: boolean
pagesUsingSizeAdjust: boolean
} }
const PLUGIN_NAME = 'FontLoaderManifestPlugin' const PLUGIN_NAME = 'FontLoaderManifestPlugin'
...@@ -50,6 +52,8 @@ export class FontLoaderManifestPlugin { ...@@ -50,6 +52,8 @@ export class FontLoaderManifestPlugin {
const fontLoaderManifest: FontLoaderManifest = { const fontLoaderManifest: FontLoaderManifest = {
pages: {}, pages: {},
app: {}, app: {},
appUsingSizeAdjust: false,
pagesUsingSizeAdjust: false,
} }
if (this.appDirEnabled) { if (this.appDirEnabled) {
...@@ -60,6 +64,12 @@ export class FontLoaderManifestPlugin { ...@@ -60,6 +64,12 @@ export class FontLoaderManifestPlugin {
/\.(woff|woff2|eot|ttf|otf)$/.test(file) /\.(woff|woff2|eot|ttf|otf)$/.test(file)
) )
if (!fontLoaderManifest.appUsingSizeAdjust) {
fontLoaderManifest.appUsingSizeAdjust = fontFiles.some((file) =>
file.includes('-s')
)
}
// Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded // Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded
const preloadedFontFiles: string[] = fontFiles.filter( const preloadedFontFiles: string[] = fontFiles.filter(
(file: string) => /\.p.(woff|woff2|eot|ttf|otf)$/.test(file) (file: string) => /\.p.(woff|woff2|eot|ttf|otf)$/.test(file)
...@@ -86,6 +96,12 @@ export class FontLoaderManifestPlugin { ...@@ -86,6 +96,12 @@ export class FontLoaderManifestPlugin {
/\.(woff|woff2|eot|ttf|otf)$/.test(file) /\.(woff|woff2|eot|ttf|otf)$/.test(file)
) )
if (!fontLoaderManifest.pagesUsingSizeAdjust) {
fontLoaderManifest.pagesUsingSizeAdjust = fontFiles.some((file) =>
file.includes('-s')
)
}
// Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded // Font files ending with .p.(woff|woff2|eot|ttf|otf) are preloaded
const preloadedFontFiles: string[] = fontFiles.filter( const preloadedFontFiles: string[] = fontFiles.filter(
(file: string) => /\.p.(woff|woff2|eot|ttf|otf)$/.test(file) (file: string) => /\.p.(woff|woff2|eot|ttf|otf)$/.test(file)
......
...@@ -382,7 +382,14 @@ function getFontLoaderLinks( ...@@ -382,7 +382,14 @@ function getFontLoaderLinks(
return { return {
preconnect: preconnectToSelf ? ( preconnect: preconnectToSelf ? (
<link rel="preconnect" href="/" crossOrigin="anonymous" /> <link
data-next-font={
fontLoaderManifest.pagesUsingSizeAdjust ? 'size-adjust' : ''
}
rel="preconnect"
href="/"
crossOrigin="anonymous"
/>
) : null, ) : null,
preload: preloadedFontFiles preload: preloadedFontFiles
? preloadedFontFiles.map((fontFile) => { ? preloadedFontFiles.map((fontFile) => {
...@@ -395,6 +402,7 @@ function getFontLoaderLinks( ...@@ -395,6 +402,7 @@ function getFontLoaderLinks(
as="font" as="font"
type={`font/${ext}`} type={`font/${ext}`}
crossOrigin="anonymous" crossOrigin="anonymous"
data-next-font={fontFile.includes('-s') ? 'size-adjust' : ''}
/> />
) )
}) })
......
...@@ -1492,7 +1492,14 @@ export async function renderToHTMLOrFlight( ...@@ -1492,7 +1492,14 @@ export async function renderToHTMLOrFlight(
return ( return (
<> <>
{preloadedFontFiles?.length === 0 ? ( {preloadedFontFiles?.length === 0 ? (
<link rel="preconnect" href="/" crossOrigin="anonymous" /> <link
data-next-font={
fontLoaderManifest?.appUsingSizeAdjust ? 'size-adjust' : ''
}
rel="preconnect"
href="/"
crossOrigin="anonymous"
/>
) : null} ) : null}
{preloadedFontFiles {preloadedFontFiles
? preloadedFontFiles.map((fontFile) => { ? preloadedFontFiles.map((fontFile) => {
...@@ -1505,6 +1512,9 @@ export async function renderToHTMLOrFlight( ...@@ -1505,6 +1512,9 @@ export async function renderToHTMLOrFlight(
as="font" as="font"
type={`font/${ext}`} type={`font/${ext}`}
crossOrigin="anonymous" crossOrigin="anonymous"
data-next-font={
fontFile.includes('-s') ? 'size-adjust' : ''
}
/> />
) )
}) })
......
...@@ -223,23 +223,26 @@ createNextDescribe( ...@@ -223,23 +223,26 @@ createNextDescribe(
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/e9b9dc0d8ba35f48.p.woff2', href: '/_next/static/media/e9b9dc0d8ba35f48-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/b61859a50be14c53.p.woff2', href: '/_next/static/media/b61859a50be14c53-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(2).attribs).toEqual({ expect($('link[as="font"]').get(2).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/b2104791981359ae.p.woff2', href: '/_next/static/media/b2104791981359ae-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
...@@ -254,24 +257,27 @@ createNextDescribe( ...@@ -254,24 +257,27 @@ createNextDescribe(
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/e9b9dc0d8ba35f48.p.woff2', href: '/_next/static/media/e9b9dc0d8ba35f48-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/e1053f04babc7571.p.woff2', href: '/_next/static/media/e1053f04babc7571-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(2).attribs).toEqual({ expect($('link[as="font"]').get(2).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/feab2c68f2a8e9a4.p.woff2', href: '/_next/static/media/feab2c68f2a8e9a4-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
...@@ -286,17 +292,19 @@ createNextDescribe( ...@@ -286,17 +292,19 @@ createNextDescribe(
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/e9b9dc0d8ba35f48.p.woff2', href: '/_next/static/media/e9b9dc0d8ba35f48-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/75c5faeeb9c86969.p.woff2', href: '/_next/static/media/75c5faeeb9c86969-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
...@@ -311,17 +319,19 @@ createNextDescribe( ...@@ -311,17 +319,19 @@ createNextDescribe(
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/e9b9dc0d8ba35f48.p.woff2', href: '/_next/static/media/e9b9dc0d8ba35f48-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: '', crossorigin: '',
href: '/_next/static/media/568e4c6d8123c4d6.p.woff2', href: '/_next/static/media/568e4c6d8123c4d6-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
}) })
...@@ -334,6 +344,12 @@ createNextDescribe( ...@@ -334,6 +344,12 @@ createNextDescribe(
// Preconnect // Preconnect
expect($('link[rel="preconnect"]').length).toBe(1) expect($('link[rel="preconnect"]').length).toBe(1)
expect($('link[rel="preconnect"]').get(0).attribs).toEqual({
crossorigin: 'anonymous',
href: '/',
rel: 'preconnect',
'data-next-font': 'size-adjust',
})
// Preload // Preload
expect($('link[as="font"]').length).toBe(0) expect($('link[as="font"]').length).toBe(0)
} }
......
import localFont from '@next/font/local'
import { Open_Sans } from '@next/font/google' import { Open_Sans } from '@next/font/google'
const openSans = Open_Sans({ const openSans = Open_Sans({
fallback: ['system-ui', 'Arial'], fallback: ['system-ui', 'Arial'],
...@@ -5,6 +6,12 @@ const openSans = Open_Sans({ ...@@ -5,6 +6,12 @@ const openSans = Open_Sans({
adjustFontFallback: false, adjustFontFallback: false,
}) })
const myFont = localFont({
fallback: ['system-ui', 'Arial'],
src: '../fonts/my-font.woff2',
adjustFontFallback: false,
})
export default function WithFonts() { export default function WithFonts() {
return ( return (
<> <>
...@@ -21,6 +28,9 @@ export default function WithFonts() { ...@@ -21,6 +28,9 @@ export default function WithFonts() {
> >
{JSON.stringify(openSans)} {JSON.stringify(openSans)}
</div> </div>
<div id="with-fallback-local" className={myFont.className}>
{JSON.stringify(myFont)}
</div>
</> </>
) )
} }
...@@ -46,9 +46,10 @@ describe('@next/font/google basepath', () => { ...@@ -46,9 +46,10 @@ describe('@next/font/google basepath', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/dashboard/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/dashboard/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
}) })
...@@ -306,16 +306,18 @@ describe('@next/font/google', () => { ...@@ -306,16 +306,18 @@ describe('@next/font/google', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/675c25f648fd6a30.p.woff2', href: '/_next/static/media/675c25f648fd6a30-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
...@@ -331,9 +333,10 @@ describe('@next/font/google', () => { ...@@ -331,9 +333,10 @@ describe('@next/font/google', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
}) })
...@@ -351,11 +354,11 @@ describe('@next/font/google', () => { ...@@ -351,11 +354,11 @@ describe('@next/font/google', () => {
.map((el) => el.attribs.href) .map((el) => el.attribs.href)
.sort() .sort()
).toEqual([ ).toEqual([
'/_next/static/media/02205c9944024f15.p.woff2', '/_next/static/media/02205c9944024f15-s.p.woff2',
'/_next/static/media/0812efcfaefec5ea.p.woff2', '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
'/_next/static/media/1deec1af325840fd.p.woff2', '/_next/static/media/1deec1af325840fd-s.p.woff2',
'/_next/static/media/ab6fdae82d1a8d92.p.woff2', '/_next/static/media/ab6fdae82d1a8d92-s.p.woff2',
'/_next/static/media/d55edb6f37902ebf.p.woff2', '/_next/static/media/d55edb6f37902ebf-s.p.woff2',
]) ])
}) })
...@@ -374,14 +377,14 @@ describe('@next/font/google', () => { ...@@ -374,14 +377,14 @@ describe('@next/font/google', () => {
.map((el) => el.attribs.href) .map((el) => el.attribs.href)
.sort() .sort()
).toEqual([ ).toEqual([
'/_next/static/media/0812efcfaefec5ea.p.woff2', '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
'/_next/static/media/4f3dcdf40b3ca86d.p.woff2', '/_next/static/media/4f3dcdf40b3ca86d-s.p.woff2',
'/_next/static/media/560a6db6ac485cb1.p.woff2', '/_next/static/media/560a6db6ac485cb1-s.p.woff2',
'/_next/static/media/686d1702f12625fe.p.woff2', '/_next/static/media/686d1702f12625fe-s.p.woff2',
'/_next/static/media/86d92167ff02c708.p.woff2', '/_next/static/media/86d92167ff02c708-s.p.woff2',
'/_next/static/media/9ac01b894b856187.p.woff2', '/_next/static/media/9ac01b894b856187-s.p.woff2',
'/_next/static/media/c9baea324111137d.p.woff2', '/_next/static/media/c9baea324111137d-s.p.woff2',
'/_next/static/media/fb68b4558e2a718e.p.woff2', '/_next/static/media/fb68b4558e2a718e-s.p.woff2',
]) ])
}) })
...@@ -398,11 +401,35 @@ describe('@next/font/google', () => { ...@@ -398,11 +401,35 @@ describe('@next/font/google', () => {
// From _app // From _app
expect($('link[as="font"]').length).toBe(1) expect($('link[as="font"]').length).toBe(1)
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload',
type: 'font/woff2',
'data-next-font': 'size-adjust',
})
})
test('font without size adjust', async () => {
const html = await renderViaHTTP(next.url, '/with-fallback')
const $ = cheerio.load(html)
expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/_next/static/media/0812efcfaefec5ea.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': '',
})
expect($('link[as="font"]').get(2).attribs).toEqual({
as: 'font',
crossorigin: 'anonymous',
href: '/_next/static/media/ab6fdae82d1a8d92.p.woff2',
rel: 'preload',
type: 'font/woff2',
'data-next-font': '',
}) })
}) })
}) })
......
...@@ -64,17 +64,19 @@ describe('@next/font/google with-font-declarations-file', () => { ...@@ -64,17 +64,19 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
// From /inter // From /inter
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/4a7f86e553ee7e51.p.woff2', href: '/_next/static/media/4a7f86e553ee7e51-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
} }
}) })
...@@ -96,17 +98,19 @@ describe('@next/font/google with-font-declarations-file', () => { ...@@ -96,17 +98,19 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
// From /roboto // From /roboto
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/9a7e84b4dd095b33.p.woff2', href: '/_next/static/media/9a7e84b4dd095b33-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
} }
}) })
...@@ -128,17 +132,19 @@ describe('@next/font/google with-font-declarations-file', () => { ...@@ -128,17 +132,19 @@ describe('@next/font/google with-font-declarations-file', () => {
expect($('link[as="font"]').get(0).attribs).toEqual({ expect($('link[as="font"]').get(0).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/0812efcfaefec5ea.p.woff2', href: '/_next/static/media/0812efcfaefec5ea-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
// From /local-font // From /local-font
expect($('link[as="font"]').get(1).attribs).toEqual({ expect($('link[as="font"]').get(1).attribs).toEqual({
as: 'font', as: 'font',
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/_next/static/media/2a931eed088772c9.p.woff2', href: '/_next/static/media/2a931eed088772c9-s.p.woff2',
rel: 'preload', rel: 'preload',
type: 'font/woff2', type: 'font/woff2',
'data-next-font': 'size-adjust',
}) })
} }
}) })
......
...@@ -49,6 +49,7 @@ describe('@next/font/google without-preloaded-fonts without _app', () => { ...@@ -49,6 +49,7 @@ describe('@next/font/google without-preloaded-fonts without _app', () => {
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/', href: '/',
rel: 'preconnect', rel: 'preconnect',
'data-next-font': 'size-adjust',
}) })
// Preload // Preload
...@@ -108,6 +109,7 @@ describe('@next/font/google no preloads with _app', () => { ...@@ -108,6 +109,7 @@ describe('@next/font/google no preloads with _app', () => {
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/', href: '/',
rel: 'preconnect', rel: 'preconnect',
'data-next-font': 'size-adjust',
}) })
// Preload // Preload
...@@ -124,6 +126,7 @@ describe('@next/font/google no preloads with _app', () => { ...@@ -124,6 +126,7 @@ describe('@next/font/google no preloads with _app', () => {
crossorigin: 'anonymous', crossorigin: 'anonymous',
href: '/', href: '/',
rel: 'preconnect', rel: 'preconnect',
'data-next-font': 'size-adjust',
}) })
// Preload // Preload
......
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