fix: improve sourcemap resolution for Turbopack and bundled code#67
fix: improve sourcemap resolution for Turbopack and bundled code#67
Conversation
Two enhancements to sourcemap handling: 1. Use LEAST_UPPER_BOUND bias when exact position lookup fails. Turbopack and other bundlers generate minified files where actual code mappings start at column 300+, but V8 captures positions at the beginning of lines. The bias finds the nearest mapping to the right. 2. Extract function names from sourcesContent when sourcemap name mappings are missing. Next.js bundles React with file/line mappings but without function name mappings. This parses the embedded source to resolve minified names like 'eY' back to 'getCustomFormFields'. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive tests for the enhanced sourcemap resolution: - extractFunctionName helper tests for various function patterns (declarations, async, arrow, methods, object properties) - LEAST_UPPER_BOUND bias test with synthetic Turbopack-style sourcemap - sourcesContent function name extraction tests - Integration test with SourceMapper Also fixes extractFunctionName to: - Properly match object property functions (name: function) - Exclude control flow keywords (if, for, while, etc.) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Yes, exactly! The When V8 captures a stack frame, it reports positions like Using For example in the Turbopack chunks I was testing: |
|
We have added As for using Wouldn't using some kind of generic |

Summary
sourcesContentwhen sourcemap name mappings are missing (resolves minified React names likeeY→getCustomFormFields)Problem
When profiling Next.js applications with Turbopack:
Position lookup failures: Turbopack generates minified files where actual code mappings start at column 300+, but V8 captures positions at the beginning of lines. The default exact-match lookup fails.
Missing function names: Next.js bundles React with file/line mappings but without function name mappings, resulting in profiles showing minified names like
eY,ak,alinstead ofrenderElement,performWork, etc.Solution
LEAST_UPPER_BOUND bias: When exact position lookup fails, try finding the nearest mapping to the right using
sourceMap.SourceMapConsumer.LEAST_UPPER_BOUND.Function name extraction: When no name is in the sourcemap, parse the embedded
sourcesContentto extract function names from the source line (handles function declarations, async functions, arrow functions, methods, and object properties).Before/After
Before:
After:
Test plan
🤖 Generated with Claude Code