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

Recover from font loader error in dev (#41251)

Check that the module has assets. This might not always be the case in
app dev if there was an error. Test added to make sure it recovers
correctly.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `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`
- [ ] Integration 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`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 6eefc9de
...@@ -54,6 +54,7 @@ export class FontLoaderManifestPlugin { ...@@ -54,6 +54,7 @@ export class FontLoaderManifestPlugin {
if (this.appDirEnabled) { if (this.appDirEnabled) {
for (const mod of fontLoaderModules) { for (const mod of fontLoaderModules) {
if (!mod.buildInfo?.assets) continue
const modAssets = Object.keys(mod.buildInfo.assets) const modAssets = Object.keys(mod.buildInfo.assets)
const fontFiles: string[] = modAssets.filter((file: string) => const fontFiles: string[] = modAssets.filter((file: string) =>
/\.(woff|woff2|eot|ttf|otf)$/.test(file) /\.(woff|woff2|eot|ttf|otf)$/.test(file)
......
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' 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 cheerio from 'cheerio'
import path from 'path' import path from 'path'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
describe('app dir next-font', () => { 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', () => {}) it('should skip next deploy for now', () => {})
return return
} }
...@@ -296,4 +297,27 @@ describe('app dir next-font', () => { ...@@ -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')
})
})
}
}) })
import Comp from './Comp' import Comp from './Comp'
import font1 from '../fonts/font1'
import font2 from '../fonts/font2' import font2 from '../fonts/font2'
export default function HomePage() { export default function HomePage() {
return ( return (
<> <>
<p className={font1.className}>Hello world</p>
<p id="root-page" className={font2.className}> <p id="root-page" className={font2.className}>
{JSON.stringify(font2)} {JSON.stringify(font2)}
</p> </p>
...@@ -11,3 +13,5 @@ export default function HomePage() { ...@@ -11,3 +13,5 @@ export default function HomePage() {
</> </>
) )
} }
export const config = { runtime: 'experimental-edge' }
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' 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 webdriver from 'next-webdriver'
import { join } from 'path' import { join } from 'path'
...@@ -30,7 +30,8 @@ describe('font-loader-in-document-error', () => { ...@@ -30,7 +30,8 @@ describe('font-loader-in-document-error', () => {
test('font loader inside _document', async () => { test('font loader inside _document', async () => {
const browser = await webdriver(next.appPort, '/') 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( expect(await getRedboxSource(browser)).toInclude(
'Font loaders cannot be used within pages/_document.js' 'Font loaders cannot be used within pages/_document.js'
) )
......
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