Repository navigation
Conversation
|
In this particular case I would love to see the upstream fix (or at least a steer / ack from the Chrome team regarding the bug) before we patch core source map machinery. Also worth checking if this has perhaps already been fixed. |
That seems independently worth looking into on the Metro side. |
This is on purpose to fix yet another issue: D68631591 |
Actually, now I remembered that I already looked at it. Filed https://issues.chromium.org/issues/395661481 which resulted in tc39/ecma426#208. |
|
Also- I removed it from the description:
This is not the cause in anyway. The cause is simply the race condition between the big bundle map and the small hot reload map. |
Keep source mapping of replaced scripts when source maps load out of order
Summary
When a newer script replaces code from an earlier script (e.g. on hot reload), both scripts' source maps claim the same original file but disagree on its content.
CompilerScriptMapping.sourceMapAttachedresolves such conflicts in favor of whichever source map finishes loading last.That works while DevTools is attached during the replacement, because the replacement script's source map attaches last. But when DevTools attaches (or reloads) after the replacement happened, all scripts are reported at once in parse order. The small source map of the replacement script can then finish loading before the large source map of the original bundle. The bundle's stale source map then takes over the original file, and the replacement script loses its mapping. Breakpoints and
debugger;statements in the replaced code then pause in the generated script instead of the original source.In React Native this reproduces reliably:
debugger;statement and let Fast Refresh apply it.This change makes conflict resolution depend on script parse order rather than source map load order. A source map no longer takes over a URL when that URL is already provided by an incompatible source map of a newer script. Compatible source maps (same content, e.g. code splitting) are still merged into one
UISourceCodeas before.Test plan
Manually reloaded DevTools with a "debugger;" statement, after a hot reload on the same script.
Added unit tests in
CompilerScriptMapping.test.ts. Both delay the older script's source map so that it finishes loading last:supports script replacement when source maps finish loading out of order: the replacement script keeps mapping toapp.js, the bundle's staleapp.jsmapping is not used, and the bundle still maps its other sources. It fails without this change.shares UISourceCodes with compatible source maps that finish loading out of order: compatible source maps loading out of order still share theUISourceCode.Ran the
models/bindingsandmodels/breakpointsunit tests in headless Chrome: allCompilerScriptMappingtests pass, and the remaining results are identical with and without this change. ESLint and clang-format are clean.Upstreaming plan
devtools-frontendrepo following the contribution guide for Meta employees OR contribution guide.