Repository navigation
fix: compose Hermes source maps for every chunk - #1516
emanueleperuffo wants to merge 2 commits into
Conversation
|
Someone is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 6eb39e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dannyhw
left a comment
There was a problem hiding this comment.
Thanks for this! I can confirm the race, on Rspack too. On the super-app-showcase trading app, the current plugin composed source maps for only 36/66 chunks, and this PR composes all 66 (4.53 MB → 3.98 MB).
Nit (non-blocking): compilation.getAssets() also returns assets that weren't written in this compilation. When rebuilding in the same process (e.g. bundle --watch with caching enabled), unchanged chunks are skipped and are still bytecode on disk, so hermesc fails on them. Normal release builds aren't affected. Recording files in assetEmitted and transforming them in afterEmit keeps the old "only files written this build" behaviour:
let emittedAssets = new Map<string, string>();
compiler.hooks.assetEmitted.tap('RepackHermesBytecodePlugin', (file, { outputPath }) => {
emittedAssets.set(file, outputPath);
});
compiler.hooks.afterEmit.tapPromise(
{ name: 'RepackHermesBytecodePlugin', stage: -100 },
async () => {
const assets = emittedAssets;
emittedAssets = new Map();
await Promise.all(
Array.from(assets, async ([file, outputPath]) => {
// …same body as now
})
);
}
);(Rspack doesn't expose webpack's compilation.emittedAssets, hence the Map.) Happy to push this if you'd like.
Sure! I'll take a look at it next Monday if it's ok. |
|
Hi @dannyhw I have pushed a new commit with your suggestions. I used a I have tried changing our patch with these changes and it works correctly, tests pass and also rebuilds work. |
Summary
HermesBytecodePluginrunshermescin theassetEmittedhooks and checks whether the chunk's.mapexists. A chunk's.mapmay not have been written yet at that moment, sohermescruns without source maps:.bundle), making the chunk biggercomposeSourceMapsis skipped, so stack traces for that chunk can't be symbolicated back to the original sourceThis change calls the
hermescfrom theafterEmithook instead, once all assets are guaranteed to be written.Our app has many lazy chunks, and most of them hit the race. With this fix, the debug info is moved from the chunks into the source maps:
Lazy chunks now ship with a composed source map, and frames resolve to the correct source file and line. The main bundle is not affected, since React Native compiles it with its own
hermescstep.Test plan