Unverified Commit ef42b84e authored by Jude Gao's avatar Jude Gao Committed by GitHub

[dev-overlay] use absolute font src url (#76229)

Fix font loading from a non-root URL:

Repro:
```
pnpm next dev test/development/app-dir/owner-stack/
```
and Visit http://localhost:3000/browser/uncaught

Shows
```
GET /browser/__nextjs_font/geist-latin.woff2 404 in 330ms
```
parent 8a6e71a4
...@@ -11,7 +11,7 @@ export const FontStyles = () => { ...@@ -11,7 +11,7 @@ export const FontStyles = () => {
font-style: normal; font-style: normal;
font-weight: 400 600; font-weight: 400 600;
font-display: swap; font-display: swap;
src: url(__nextjs_font/geist-latin-ext.woff2) format('woff2'); src: url(/__nextjs_font/geist-latin-ext.woff2) format('woff2');
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
...@@ -23,7 +23,7 @@ export const FontStyles = () => { ...@@ -23,7 +23,7 @@ export const FontStyles = () => {
font-style: normal; font-style: normal;
font-weight: 400 600; font-weight: 400 600;
font-display: swap; font-display: swap;
src: url(__nextjs_font/geist-mono-latin-ext.woff2) format('woff2'); src: url(/__nextjs_font/geist-mono-latin-ext.woff2) format('woff2');
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
...@@ -35,7 +35,7 @@ export const FontStyles = () => { ...@@ -35,7 +35,7 @@ export const FontStyles = () => {
font-style: normal; font-style: normal;
font-weight: 400 600; font-weight: 400 600;
font-display: swap; font-display: swap;
src: url(__nextjs_font/geist-latin.woff2) format('woff2'); src: url(/__nextjs_font/geist-latin.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
...@@ -46,7 +46,7 @@ export const FontStyles = () => { ...@@ -46,7 +46,7 @@ export const FontStyles = () => {
font-style: normal; font-style: normal;
font-weight: 400 600; font-weight: 400 600;
font-display: swap; font-display: swap;
src: url(__nextjs_font/geist-mono-latin.woff2) format('woff2'); src: url(/__nextjs_font/geist-mono-latin.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { assertHasRedbox } from 'next-test-utils'
describe('DevErrorOverlay', () => { describe('DevErrorOverlay', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -28,4 +29,29 @@ describe('DevErrorOverlay', () => { ...@@ -28,4 +29,29 @@ describe('DevErrorOverlay', () => {
const code = await errorCode.getAttribute('data-nextjs-error-code') const code = await errorCode.getAttribute('data-nextjs-error-code')
expect(code).toBe('E209') expect(code).toBe('E209')
}) })
it('loads fonts successfully', async () => {
const woff2Requests: { url: string; status: number }[] = []
const browser = await next.browser('/known-rsc-error', {
beforePageLoad: (page) => {
page.route('**/*.woff2', async (route) => {
const response = await route.fetch()
woff2Requests.push({
url: route.request().url(),
status: response.status(),
})
await route.continue()
})
},
})
await assertHasRedbox(browser)
await browser.waitForIdleNetwork()
// Verify woff2 files were requested and loaded successfully
expect(woff2Requests.length).toBeGreaterThan(0)
for (const request of woff2Requests) {
expect(request.status).toBe(200)
}
})
}) })
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