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

[dev-overlay] Only warn once per invalid sourcemap #77444

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bench/nested-deps/components/**/*
**/.tina/__generated__/**
test/lib/amp-validator-wasm.js
test/production/pages-dir/production/fixture/amp-validator-wasm.js
test/e2e/app-dir/server-source-maps/fixtures/default/app/bad-sourcemap/page.js
test/e2e/app-dir/server-source-maps/fixtures/default/internal-pkg/ignored.js
test/e2e/app-dir/server-source-maps/fixtures/default/internal-pkg/sourcemapped.js
test/e2e/app-dir/server-source-maps/fixtures/default/external-pkg/sourcemapped.js
Expand Down
13 changes: 12 additions & 1 deletion packages/next/src/server/patch-error-inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface IgnoreableStackFrame extends StackFrame {

type SourceMapCache = Map<
string,
{ map: SyncSourceMapConsumer; payload: ModernSourceMapPayload }
null | { map: SyncSourceMapConsumer; payload: ModernSourceMapPayload }
>

function frameToString(frame: StackFrame): string {
Expand Down Expand Up @@ -208,6 +208,9 @@ function getSourcemappedFrameIfPossible(
console.error(
`${sourceURL}: Invalid source map. Only conformant source maps can be used to find the original code. Cause: ${cause}`
)
// If loading fails once, it'll fail every time.
// So set the cache to avoid duplicate errors.
sourceMapCache.set(frame.file, null)
// Don't even fall back to the bundler because it might be not as strict
// with regards to parsing and then we fail later once we consume the
// source map payload.
Expand Down Expand Up @@ -235,12 +238,20 @@ function getSourcemappedFrameIfPossible(
console.error(
`${sourceURL}: Invalid source map. Only conformant source maps can be used to find the original code. Cause: ${cause}`
)
// If creating the consumer fails once, it'll fail every time.
// So set the cache to avoid duplicate errors.
sourceMapCache.set(frame.file, null)
return createUnsourcemappedFrame(frame)
}
sourceMapCache.set(frame.file, {
map: sourceMapConsumer,
payload: sourceMapPayload,
})
} else if (sourceMapCacheEntry === null) {
// We failed earlier getting the payload or consumer.
// Just return an unsourcemapped frame.
// Errors will already be logged.
return createUnsourcemappedFrame(frame)
} else {
sourceMapConsumer = sourceMapCacheEntry.map
sourceMapPayload = sourceMapCacheEntry.payload
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

import { connection } from 'next/server'

function logError() {
console.error(new Error('Boom!'))
}

export default async function Page() {
await connection()
console.error(new Error('Boom!'))
logError()
return <p>Hello, Dave!</p>
}
12 changes: 10 additions & 2 deletions test/e2e/app-dir/server-source-maps/server-source-maps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ describe('app-dir - server source maps', () => {
// Node.js is fine with invalid URLs in index maps apparently.
'' +
'\nError: Boom!' +
'\n at Page (custom://[badhost]/app/bad-sourcemap/page.js:9:15)' +
'\n at logError (custom://[badhost]/app/bad-sourcemap/page.js:8:16)' +
'\n at Page (custom://[badhost]/app/bad-sourcemap/page.js:13:2)' +
// TODO: Remove blank line
'\n'
)
Expand All @@ -282,8 +283,15 @@ describe('app-dir - server source maps', () => {
'' +
`\nwebpack-internal:///(rsc)/./app/bad-sourcemap/page.js: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null` +
'\nError: Boom!' +
'\n at Page (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:15:19)'
'\n at logError (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:14:19)' +
'\n at Page (webpack-internal:///(rsc)/./app/bad-sourcemap/page.js:18:5)'
)
// Expect the invalid sourcemap warning only once.
expect(
normalizeCliOutput(next.cliOutput.slice(outputIndex)).split(
'Invalid source map.'
).length - 1
).toEqual(1)
}
} else {
// TODO: test `next start` with `--enable-source-maps`
Expand Down
Loading