Repository navigation
Closed
Copy link
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Description
When building a Flutter web app with both --web-content-hash and --source-maps (e.g., flutter build web --wasm --web-content-hash --source-maps or flutter build web --web-content-hash --source-maps), build/web/precache_manifest.json records "urlHashed": false and a mismatched "hash" for main.dart.<hash>.js:
{
"url": "main.dart.216ed961.js",
"hash": "fca793b5",
"size": 6079674,
"urlHashed": false
}Root Cause
- In
_hashAndRenameWebOutput,flutter_toolscomputescontentHash(216ed961) from the initialmain.dart.jsbytes (when its trailing comment is still//# sourceMappingURL=main.dart.js.map), derivesnewBasename = 'main.dart.216ed961.js', and then rewrites the trailingsourceMappingURLdirective insidemain.dart.jsin-place to//# sourceMappingURL=main.dart.216ed961.js.mapbefore renaming the file on disk ( additionally stripping any trailing newline due to\s*$matching\nbefore EOF). - Later, during
WebReleaseBundle.build,updatePrecacheManifesthashes the finalbuild/web/main.dart.216ed961.jsbytes on disk—which now contain the rewrittensourceMappingURLcomment—producing a different hash (fca793b5). - Because
'main.dart.216ed961.js'.contains('.fca793b5.')isfalse,updatePrecacheManifestsets"urlHashed": falseand"hash": "fca793b5", breaking cache validation and precache manifest consumers that rely onurlHashed: trueand filename/content hash parity.
Other Affected Files
main.dart.<hash>.js(Dart2JSTargetand the JS fallback in--wasmbuilds): Affected when--source-mapsis passed.main.dart.<hash>.mjs.map(Dart2WasmTarget): If a.mjs.mapfile is present alongsidemain.dart.mjs,Dart2WasmTargetpreviously derivedjsSupportMapName = '$jsSupportName.map'.flutter_service_worker.js/worker.<hash>.js: Uses_hashAndRenameWebOutputwithsourceMapFileif present.main.dart.<hash>.wasm: Not affected (_hashAndRenameWebOutputskipssourceMappingURLrewriting whenisWasmistruebecause.wasmembedsmain.dart.wasm.mapin a binary custom section).
Proposed Fix (Hash Inversion)
In _hashAndRenameWebOutput (packages/flutter_tools/lib/src/build_system/targets/web.dart):
- Hash
sourceMapFilefirst (mapHash) and rename it viacomputeHashedBasename(oldMapBasename, mapHash, file.fileSystem)(producingmain.dart.<mapHash>.js.map,main.dart.<mapHash>.mjs.map,worker.<mapHash>.js.map). - Rewrite
//# sourceMappingURL=<newMapBasename>infile(using positive lookahead(?=\s*$)so trailing newlines are preserved). - Compute
contentHashfrom the final bytes offileand renamefiletomain.dart.<contentHash>.jsso its filename hash matches its on-disk bytes andupdatePrecacheManifestrecords"urlHashed": truewith the matching"hash". - Resolve
mainJsMapNameinDart2JSTarget.buildFilesandjsSupportMapNameinDart2WasmTarget.buildFilesvia_resolveHashedBasename.
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work listtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Activity
Validate `precache_manifest.json` (`F-07`, `F-08`) and `--source-maps…
test(redteam): verify Chrome Debugger.scriptParsed source maps for Wa…
fix(web): hash source maps before rewriting sourceMappingURL with --w…
github-actions commentedon Oct 15, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.fix(web): hash source maps before rewriting sourceMappingURL with --w…