Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover from font loader error in dev #41251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,6 +54,7 @@ export class FontLoaderManifestPlugin {

if (this.appDirEnabled) {
for (const mod of fontLoaderModules) {
if (!mod.buildInfo?.assets) continue
const modAssets = Object.keys(mod.buildInfo.assets)
const fontFiles: string[] = modAssets.filter((file: string) =>
/\.(woff|woff2|eot|ttf|otf)$/.test(file)
Expand Down
28 changes: 26 additions & 2 deletions test/e2e/app-dir/next-font.test.ts
@@ -1,12 +1,13 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import { getRedboxSource, hasRedbox, renderViaHTTP } from 'next-test-utils'
import cheerio from 'cheerio'
import path from 'path'
import webdriver from 'next-webdriver'

describe('app dir next-font', () => {
if ((global as any).isNextDeploy || (global as any).isNextDev) {
const isDev = (global as any).isNextDev
if ((global as any).isNextDeploy) {
it('should skip next deploy for now', () => {})
return
}
Expand Down Expand Up @@ -296,4 +297,27 @@ describe('app dir next-font', () => {
})
})
})

if (isDev) {
describe('Dev errors', () => {
it('should recover on font loader error', async () => {
const browser = await webdriver(next.url, '/')
const font1Content = await next.readFile('fonts/font1.js')

// Break file
await next.patchFile(
'fonts/font1.js',
font1Content.replace('./font1.woff2', './does-not-exist.woff2')
)
expect(await hasRedbox(browser, true)).toBeTrue()
expect(await getRedboxSource(browser)).toInclude(
"Can't resolve './does-not-exist.woff2'"
)

// Fix file
await next.patchFile('fonts/font1.js', font1Content)
await browser.waitForElementByCss('#root-page')
})
})
}
})
4 changes: 4 additions & 0 deletions test/e2e/app-dir/next-font/app/page.js
@@ -1,13 +1,17 @@
import Comp from './Comp'
import font1 from '../fonts/font1'
import font2 from '../fonts/font2'

export default function HomePage() {
return (
<>
<p className={font1.className}>Hello world</p>
<p id="root-page" className={font2.className}>
{JSON.stringify(font2)}
</p>
<Comp />
</>
)
}

export const config = { runtime: 'experimental-edge' }
5 changes: 3 additions & 2 deletions test/e2e/next-font/font-loader-in-document-error.test.ts
@@ -1,6 +1,6 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { check, getRedboxSource } from 'next-test-utils'
import { getRedboxSource, hasRedbox } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'

Expand Down Expand Up @@ -30,7 +30,8 @@ describe('font-loader-in-document-error', () => {

test('font loader inside _document', async () => {
const browser = await webdriver(next.appPort, '/')
await check(() => getRedboxSource(browser), /Font loaders/)
expect(await hasRedbox(browser, true)).toBeTrue()
expect(await getRedboxSource(browser)).toMatch(/Font loaders/)
expect(await getRedboxSource(browser)).toInclude(
'Font loaders cannot be used within pages/_document.js'
)
Expand Down