Unverified Commit 3bd2711c authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

[Fast Refresh] Improve responsiveness on Windows (#12909)

parent c2127899
...@@ -11,24 +11,28 @@ export const base = curry(function base( ...@@ -11,24 +11,28 @@ export const base = curry(function base(
config.target = ctx.isServer ? 'node' : 'web' config.target = ctx.isServer ? 'node' : 'web'
// https://webpack.js.org/configuration/devtool/#development // https://webpack.js.org/configuration/devtool/#development
config.devtool = ctx.isDevelopment if (ctx.isDevelopment) {
? ctx.isReactRefreshEnabled if (ctx.isReactRefreshEnabled) {
? ctx.isServer if (ctx.isServer || process.platform === 'win32') {
? // Non-eval based source maps are very slow to rebuild, so we only // Non-eval based source maps are slow to rebuild, so we only enable
// enable them for the server. Unfortunately, eval source maps are // them for the server and Windows. Unfortunately, eval source maps
// not supported by Node.js. // are not supported by Node.js, and are slow on Windows.
'inline-source-map' config.devtool = 'inline-source-map'
: // `eval-source-map` provides full-fidelity source maps for the } else {
// original source, including columns and original variable names. // `eval-source-map` provides full-fidelity source maps for the
// This is desirable so the in-browser debugger can correctly pause // original source, including columns and original variable names.
// and show scoped variables with their original names. // This is desirable so the in-browser debugger can correctly pause
'eval-source-map' // and show scoped variables with their original names.
: // `cheap-module-source-map` is the old preferred format that was config.devtool = 'eval-source-map'
// required for `react-error-overlay`. }
'cheap-module-source-map' } else {
: ctx.isProduction // `cheap-module-source-map` is the old preferred format that was
? false // required for `react-error-overlay`.
: false config.devtool = 'cheap-module-source-map'
}
} else {
config.devtool = false
}
if (!config.module) { if (!config.module) {
config.module = { rules: [] } config.module = { rules: [] }
......
import { parse as parseStack } from 'stacktrace-parser'
import * as Bus from './internal/bus' import * as Bus from './internal/bus'
import { parseStack } from './internal/helpers/parseStack'
let isRegistered = false let isRegistered = false
let stackTraceLimit: number | undefined = undefined let stackTraceLimit: number | undefined = undefined
......
...@@ -4,7 +4,7 @@ import { getSourceMapUrl } from './getSourceMapUrl' ...@@ -4,7 +4,7 @@ import { getSourceMapUrl } from './getSourceMapUrl'
export function getRawSourceMap(fileContents: string): RawSourceMap | null { export function getRawSourceMap(fileContents: string): RawSourceMap | null {
const sourceUrl = getSourceMapUrl(fileContents) const sourceUrl = getSourceMapUrl(fileContents)
if (sourceUrl == null) { if (!sourceUrl?.startsWith('data:')) {
return null return null
} }
......
import { parse, StackFrame } from 'stacktrace-parser'
const regexNextStatic = /\/_next(\/static\/.+)/g
export function parseStack(stack: string): StackFrame[] {
const frames = parse(stack)
return frames.map(frame => {
try {
const url = new URL(frame.file)
const res = regexNextStatic.exec(url.pathname)
if (res) {
const distDir = process.env.__NEXT_DIST_DIR
?.replace(/\\/g, '/')
?.replace(/\/$/, '')
if (distDir) {
frame.file = 'file://' + distDir.concat(res.pop())
}
}
} catch {}
return frame
})
}
...@@ -101,17 +101,31 @@ test('logbox: can recover from a event handler error', async () => { ...@@ -101,17 +101,31 @@ test('logbox: can recover from a event handler error', async () => {
).toBe('1') ).toBe('1')
expect(await session.hasRedbox(true)).toBe(true) expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` if (process.platform === 'win32') {
"index.js (8:16) @ eval expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"index.js (8:16) @ <unknown>
6 | const increment = useCallback(() => {
7 | setCount(c => c + 1) 6 | const increment = useCallback(() => {
> 8 | throw new Error('oops') 7 | setCount(c => c + 1)
| ^ > 8 | throw new Error('oops')
9 | }, [setCount]) | ^
10 | return ( 9 | }, [setCount])
11 | <main>" 10 | return (
`) 11 | <main>"
`)
} else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"index.js (8:16) @ eval
6 | const increment = useCallback(() => {
7 | setCount(c => c + 1)
> 8 | throw new Error('oops')
| ^
9 | }, [setCount])
10 | return (
11 | <main>"
`)
}
await session.patch( await session.patch(
'index.js', 'index.js',
...@@ -466,17 +480,31 @@ test('syntax > runtime error', async () => { ...@@ -466,17 +480,31 @@ test('syntax > runtime error', async () => {
await new Promise(resolve => setTimeout(resolve, 1000)) await new Promise(resolve => setTimeout(resolve, 1000))
expect(await session.hasRedbox(true)).toBe(true) expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` if (process.platform === 'win32') {
"index.js (6:14) @ eval expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"index.js (6:14) @ <unknown>
4 | setInterval(() => {
5 | i++ 4 | setInterval(() => {
> 6 | throw Error('no ' + i) 5 | i++
| ^ > 6 | throw Error('no ' + i)
7 | }, 1000) | ^
8 | export default function FunctionNamed() { 7 | }, 1000)
9 | return <div />" 8 | export default function FunctionNamed() {
`) 9 | return <div />"
`)
} else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"index.js (6:14) @ eval
4 | setInterval(() => {
5 | i++
> 6 | throw Error('no ' + i)
| ^
7 | }, 1000)
8 | export default function FunctionNamed() {
9 | return <div />"
`)
}
// Make a syntax error. // Make a syntax error.
await session.patch( await session.patch(
......
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