Skip to content

fix(web): hash source maps before rewriting sourceMappingURL with --web-content-hash - #193614

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
kevmoo:content_hash_source_maps
Oct 1, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:masterfrom
kevmoo:content_hash_source_maps

Conversation

@kevmoo

@kevmoo kevmoo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a content-hash mismatch when combining --web-content-hash and --source-maps in flutter build web:

  • Hash and rename sourceMapFile before rewriting sourceMappingURL (_hashAndRenameWebOutput):
    • Previously, _hashAndRenameWebOutput (packages/flutter_tools/lib/src/build_system/targets/web.dart) hashed main.dart.js before rewriting its trailing //# sourceMappingURL=main.dart.js.map comment in-place (and stripped the trailing newline because \s*$ matched \n before EOF).
    • When updatePrecacheManifest (packages/flutter_tools/lib/src/web/content_hash.dart) later hashed the final build/web/main.dart.<hash>.js bytes on disk, the rewritten sourceMappingURL comment produced a different SHA-256 prefix, causing precache_manifest.json to emit "urlHashed": false and a mismatched "hash" for main.dart.<hash>.js.
    • _hashAndRenameWebOutput now hashes sourceMapFile first (mapHash), renames it via computeHashedBasename(oldMapBasename, mapHash, file.fileSystem) (main.dart.<mapHash>.js.map, main.dart.<mapHash>.mjs.map, worker.<mapHash>.js.map), rewrites //# sourceMappingURL=<newMapBasename> in the code file using a positive lookahead (?=\s*$) so trailing newlines are preserved, and then hashes and renames the code file (contentHash) so its filename hash matches its final on-disk bytes.
  • Resolve hashed source map basenames in Dart2JSTarget.buildFiles and Dart2WasmTarget.buildFiles:
    • Uses _resolveHashedBasename(environment.buildDir, _mainJsMapRegex, 'main.dart.js.map') and _resolveHashedBasename(environment.buildDir, _mainMjsMapRegex, 'main.dart.mjs.map') when compilerConfig.webContentHash is enabled so WebReleaseBundle copies the independently content-hashed .map files to build/web/.

Related Issues

Tests

  • Updated source map hashing unit tests in packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart to verify independent map and code content hashes and trailing newline preservation.
  • Added a regression test (hashAndRenameWebOutput with sourceMapFile produces matching hash and urlHashed: true in updatePrecacheManifest) verifying end-to-end parity between _hashAndRenameWebOutput and updatePrecacheManifest.

…b-content-hash`

When `--web-content-hash` and `--source-maps` were combined,
`_hashAndRenameWebOutput` previously hashed `main.dart.js` before
rewriting its trailing `//# sourceMappingURL=` comment, causing the
on-disk file bytes to diverge from the filename's content hash and
producing `"urlHashed": false` in `precache_manifest.json`.

Hash and rename `sourceMapFile` first (`main.dart.<mapHash>.js.map`,
`main.dart.<mapHash>.mjs.map`, `worker.<mapHash>.js.map`), rewrite the
`sourceMappingURL` directive in the code file while preserving trailing
newlines, and then hash and rename the code file so its filename hash
matches its final on-disk bytes.

Fixes flutter#193601
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 1, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the web build target logic to hash and rename source maps before hashing the main JS/MJS files, ensuring that the sourceMappingURL comment matches the final on-disk content hash. Feedback suggests optimizing Dart2JSTarget and Dart2WasmTarget by avoiding redundant synchronous directory listings (listSync) when resolving hashed map names, recommending instead to match the file's basename against the regex directly within the directory listing's filter.

Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart Outdated
Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart Outdated
kevmoo added a commit to kevmoo/flutter_web_cache_check that referenced this pull request Oct 1, 2026
…` in S12/S15 (#8)

* Validate `precache_manifest.json` (`F-07`, `F-08`) and `--source-maps` in S12/S15

- Add `F-07` (`precache_manifest.json` revalidation check) and `F-08`
  (`precache_manifest.json` entry `urlHashed` / hash integrity, missing
  hashed entrypoints, and `.map` / `.symbols` / `.info.json` exclusion) to
  `UrlChecker`.
- Add `sourceMaps` (`--source-maps`) to `BuildOptions` in `redteam_harness`
  and enable it in `S12` (`PrecacheManifestScenario`) and `S15`
  (`CacheCheckDogfoodScenario`) to catch `--web-content-hash` +
  `--source-maps` hash corruption (flutter/flutter#193601,
  flutter/flutter#193614).

* Use Dart 3 map pattern matching in `UrlChecker` precache manifest validation
kevmoo added a commit to kevmoo/flutter_web_cache_check that referenced this pull request Oct 1, 2026
…sm and JS (#9)

- Enable the CDP `Debugger` domain in `ChromeSession` and capture
  `Debugger.scriptParsed` events (`ParsedScriptRecord`) including
  `sourceMapURL` and `scriptLanguage`.
- Update `S12` (`PrecacheManifestScenario`) to verify that:
  - `main.dart.wasm.map` resolves (`200 OK`) with valid Source Map v3 JSON
    (`version: 3`, non-empty `sources` and `mappings`).
  - Live headless Chrome emits `Debugger.scriptParsed` with
    `sourceMapURL: "main.dart.wasm.map"` for `main.dart.<hash>.wasm` and a
    content-hashed `main.dart.<mapHash>.js.map` for `main.dart.<hash>.js`,
    and can fetch and parse both `.map` files as valid Source Map v3 JSON.

Refs: flutter/flutter#193601
Refs: flutter/flutter#193614
@kevmoo
kevmoo requested a review from mdebbar October 1, 2026 02:09
mdebbar
mdebbar previously approved these changes Oct 1, 2026
Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart Outdated
… and web.dart

Extract `computeShortContentHash(List<int> bytes)` in `content_hash.dart`
and use it in `_hashAndRenameWebOutput`, `hashWebAssets`, and
`updatePrecacheManifest` so all 8-character SHA-256 content hashes share a
single source of truth.
@kevmoo kevmoo added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 1, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 1, 2026
Merged via the queue into flutter:master with commit 9286bbf Oct 1, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 1, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Oct 1, 2026
…13104)

Manual roll requested by [email protected]

flutter/flutter@d649d2b...e89fd0a

2026-10-01 [email protected] Manual roll ICU from 6ebb40c59477 to 5aa526207171 (2 revisions) (flutter/flutter#193661)
2026-10-01 [email protected] fix(web): hash source maps before rewriting sourceMappingURL with --web-content-hash (flutter/flutter#193614)
2026-10-01 [email protected] [flutter_tools] Bootstrap DeviceManager in ToolDependencies (flutter/flutter#193524)
2026-10-01 [email protected] [wasm] Set flutter_runtime_mode in tools/gn to_gn_wasm_args (flutter/flutter#193407)
2026-10-01 [email protected] Remove remaining `download_jdk` references (flutter/flutter#193562)
2026-10-01 [email protected] Synchronize dart2wasm feature probes in roll script and flutter_bootstrap.js (flutter/flutter#193271)
2026-10-01 [email protected] [web] Unskip web tests that now pass in gestures, services, and widgets (flutter/flutter#193512)
2026-10-01 [email protected] Roll Fuchsia Test Scripts from whZAV1mfT-Rdc0rQ8... to fCNknap4ZI0AMcvIf... (flutter/flutter#193640)
2026-10-01 [email protected] Roll Skia from 0575a37d0619 to f2d68e0b8863 (2 revisions) (flutter/flutter#193621)
2026-10-01 [email protected] perf(widgets): use const <Never>{} in InheritedModelElement and avoid redundant casts in RenderObjectElement.update (flutter/flutter#192913)
2026-10-01 [email protected] [web] Unskip and strengthen missing glyph tofu test on Wimp (flutter/flutter#193426)
2026-10-01 [email protected] [flutter_tools] Fix `flutter drive -d chrome` hanging on web (flutter/flutter#193459)
2026-10-01 [email protected] [web] Fix hang when Chromium cannot bind remote debugging port (flutter/flutter#193461)
2026-10-01 [email protected] [flutter_tools] Bundle data assets from hooks in flutter test (flutter/flutter#193435)
2026-10-01 [email protected] Roll Packages from 0ba9a82 to d5ec6db (11 revisions) (flutter/flutter#193641)
2026-10-01 [email protected] Revert: [flutter_tools] Fix DTD "Stream already subscribed" error and wait for analysis over DTD in widget preview (flutter/flutter#193637)
2026-10-01 [email protected] Roll Skia from 6182a3cf8f98 to 0575a37d0619 (5 revisions) (flutter/flutter#193613)
2026-10-01 [email protected] [flutter_tools] Fix DTD "Stream already subscribed" error and wait for analysis over DTD in widget preview (flutter/flutter#192930)
2026-09-30 [email protected] [Impeller] Sample the render target rect in offscreen advanced blends (flutter/flutter#192988)
2026-09-30 [email protected] Roll Skia from 01524014dff5 to 6182a3cf8f98 (11 revisions) (flutter/flutter#193594)
2026-09-30 [email protected] [web] Use Xvfb -displayfd and clean up Xvfb after Firefox test suites (flutter/flutter#193510)
2026-09-30 [email protected] Fixes bug where sibling node fail to update size (flutter/flutter#191220)
2026-09-30 [email protected] Roll Skia from c7b323126bf0 to 01524014dff5 (3 revisions) (flutter/flutter#193577)
2026-09-30 [email protected] Remove some Undefined Behavior from run_customer_testing_tests.dart. (flutter/flutter#193582)
2026-09-30 [email protected] Fix pointer id/coordinate mismatch in Android platform view multi-touch (flutter/flutter#191631)
2026-09-30 [email protected] Roll Packages from 3c6ce59 to 0ba9a82 (11 revisions) (flutter/flutter#193578)
2026-09-30 [email protected] Fix unresolved doc comment references in dev/ tooling (flutter/flutter#193501)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@kevmoo
kevmoo deleted the content_hash_source_maps branch October 2, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] Fix --web-content-hash breaking cache when --source-maps is used

2 participants