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

Ensure error is cleared for missing global css #36292

Merged
merged 2 commits into from Apr 20, 2022
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
3 changes: 2 additions & 1 deletion packages/next/server/render.tsx
Expand Up @@ -78,6 +78,7 @@ import {
import { ImageConfigContext } from '../shared/lib/image-config-context'
import { FlushEffectsContext } from '../shared/lib/flush-effects'
import { interopDefault } from '../lib/interop-default'
import stripAnsi from 'next/dist/compiled/strip-ansi'

let optimizeAmp: typeof import('./optimize-amp').default
let getFontDefinitionFromManifest: typeof import('./font-utils').getFontDefinitionFromManifest
Expand Down Expand Up @@ -1744,7 +1745,7 @@ export async function renderToHTML(
function errorToJSON(err: Error) {
return {
name: err.name,
message: err.message,
message: stripAnsi(err.message),
stack: err.stack,
middleware: (err as any).middleware,
}
Expand Down
45 changes: 45 additions & 0 deletions test/development/acceptance/ReactRefreshLogBox-builtins.test.ts
Expand Up @@ -100,4 +100,49 @@ describe('ReactRefreshLogBox', () => {

await cleanup()
})

test('Module not found (missing global CSS)', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'pages/_app.js',
`
import './non-existent.css'

export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
`,
],
[
'pages/index.js',
`
export default function Page(props) {
return <p>index page</p>
}
`,
],
])
)
expect(await session.hasRedbox(true)).toBe(true)

const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()

await session.patch(
'pages/_app.js',
`
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
`
)
expect(await session.hasRedbox(false)).toBe(false)
expect(
await session.evaluate(() => document.documentElement.innerHTML)
).toContain('index page')

await cleanup()
})
})
Expand Up @@ -11,6 +11,19 @@ Module not found: Can't resolve 'b'
https://nextjs.org/docs/messages/module-not-found"
`;

exports[`ReactRefreshLogBox Module not found (missing global CSS) 1`] = `
"./pages/_app.js:2:8
Module not found: Can't resolve './non-existent.css'
1 |
> 2 | import './non-existent.css'
| ^
3 |
4 | export default function App({ Component, pageProps }) {
5 | return <Component {...pageProps} />

https://nextjs.org/docs/messages/module-not-found"
`;

exports[`ReactRefreshLogBox Module not found 1`] = `
"./index.js:1:0
Module not found: Can't resolve 'b'
Expand Down