Skip to content

feat(web): support --web-content-hash for entrypoint files - #190153

Merged
auto-submit[bot] merged 13 commits into
flutter:masterfrom
kevmoo:web-content-hash-phase-1
Sep 10, 2026
Merged

auto-submit[bot] merged 13 commits into
flutter:masterfrom
kevmoo:web-content-hash-phase-1

Conversation

@kevmoo

@kevmoo kevmoo commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Enables content-hashed filenames for web build outputs (main.dart.<hash>.js, .wasm, .mjs) via the optional --web-content-hash flag in flutter build web.

  • Adds typed WebOptions.webContentHash descriptor to WebCoreOptionsBundle.
  • Implements _hashAndRenameWebOutput in web.dart to compute SHA-256 digests of compiled entrypoint binaries and rename outputs on disk.
  • Dynamically discovers hashed entrypoint URLs in Dart2WebTarget.getBuildConfig and embeds them into flutter_bootstrap.js.
  • Preserves unhashed main.dart.wasm.map to maintain WebAssembly binary sourceMappingURL custom section integrity.
  • Unconditionally prunes stale entrypoint files from build/web/ across repeated builds.
  • Fast-fails build if web/index.html contains direct <script src="main.dart.js"> tags or deprecated FlutterLoader.loadEntrypoint calls.
  • Emits post-build serving tip linking to web deployment caching guidance.

Fixes #191914
Part of #149031

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 28, 2026
@kevmoo kevmoo changed the title web content hash phase 1 feat(web): support --web-content-hash for entrypoint files Jul 28, 2026
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) d: examples Sample code and demos team-android Owned by Android platform team labels Aug 12, 2026
@kevmoo
kevmoo marked this pull request as ready for review August 12, 2026 07:18
@kevmoo
kevmoo requested a review from a team as a code owner August 12, 2026 07:18
@kevmoo
kevmoo requested review from jesswrd and removed request for a team August 12, 2026 07:18

@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 introduces a --web-content-hash flag to the Flutter web build command, which appends content hashes to the filenames of web output files (such as JavaScript, WebAssembly, and source maps) to prevent caching issues. The review feedback highlights a critical issue where attempting to read binary .wasm files as UTF-8 strings to update source map references causes performance bottlenecks and failures. Additionally, renaming .wasm.map files breaks the internal sourceMappingURL reference inside the .wasm binary. The feedback suggests keeping .wasm.map files unhashed, skipping string replacement on .wasm binaries, and updating the build targets and pattern stems accordingly.

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
Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart
@kevmoo
kevmoo force-pushed the web-content-hash-phase-1 branch from d5ee436 to 57cec35 Compare August 12, 2026 07:24
@github-actions github-actions Bot removed a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) d: examples Sample code and demos team-android Owned by Android platform team labels Aug 12, 2026
@jesswrd jesswrd added the CICD Run CI/CD label Aug 26, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

Include an 8-character content hash in the filenames of compiled web
entrypoints (for example, 'main.dart.<hash>.js', 'main.dart.<hash>.wasm',
'main.dart.<hash>.mjs', and paired source maps) so web servers can serve
executable assets with 'Cache-Control: max-age=31536000, immutable'.

* Register typed 'WebOptions.webContentHash' flag descriptor in 'WebCoreOptionsBundle'.
* Validate 'web/index.html' during 'build web' and fast-fail if legacy direct
  'main.dart.js' script tags or deprecated 'FlutterLoader.loadEntrypoint' APIs are present.
* Hash and rename dart2js and dart2wasm outputs, update source map comments,
  and rewrite 'dart2js.d' and 'dart2wasm.d' depfiles.
* Preserve unhashed 'main.dart.wasm.map' to maintain WASM binary section integrity.
* Dynamically discover hashed entrypoints in 'Dart2WebTarget.getBuildConfig'
  and inject them into 'flutter_bootstrap.js'.
* Prune stale hashed entrypoint files from 'build/web/' across repeated builds.
* Emit serving tip linking to web deployment caching guidance.
@kevmoo
kevmoo force-pushed the web-content-hash-phase-1 branch from 588414b to 31a2383 Compare August 27, 2026 20:02
* Scan 'compileTargets' directly in 'WebTemplatedFiles.buildConfigString' to
  ensure 'wasmHashes' is accurately populated on clean builds before outputs
  are copied.
* Harden 'Dart2JSTarget.getBuildConfig' and 'Dart2WasmTarget.getBuildConfig'
  to safely resolve entrypoints when residual or unhashed files exist in buildDir.
* Unconditionally clean up stale entrypoints in 'WebReleaseBundle.build' across
  both hashed and unhashed builds to prevent service worker cache pollution.
* Scope sourceMappingURL comment rewriting to the trailing directive line.
* Use 'project.web.indexFile' and filter HTML comments during index.html validation.
* Support compound extensions like '.js.map' in '_computeHashedBasename'.
Comment thread packages/flutter_tools/lib/src/commands/build_web.dart Outdated
@kevmoo

kevmoo commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces the --web-content-hash flag to include content hashes in compiled web entrypoint filenames, preventing browsers from serving stale cached files. It implements renaming logic, updates target configurations, handles cleanup of outdated entrypoints, and adds comprehensive tests. The review feedback identifies two opportunities to improve cleanup: first, by removing stale .part.js and .part.js.map files from the build directory to avoid false-positive tool exits on subsequent builds; and second, by updating _entrypointFileRegex to match and clean up deferred Wasm modules when switching build configurations.

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
Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart
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
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
Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/build_web.dart Outdated
- Guard against non-existent build directory and sort by last modified time in _resolveHashedBasename
- Anchor _partFileRegex with $ and reuse static _partFileMapRegex in buildFiles
- Scope CanvasKit WASM exclusion to relative buildDir path to avoid ancestor directory collisions
- Extend _entrypointFileRegex to match deferred part files during cleanup
- Use inherited logger.printStatus in BuildWebCommand
- Add unit tests for candidate sorting, canvaskit path scoping, and part file cleanup
@kevmoo kevmoo added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 10, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 10, 2026
Merged via the queue into flutter:master with commit f798084 Sep 10, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 10, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 12, 2026
Roll Flutter from 63b9518f16bc to 2553f89be1ef (62 revisions)

flutter/flutter@63b9518...2553f89

2026-09-12 [email protected] Roll clang to 07d67299a15ce03b053736e2d31a668ee0576987 (flutter/flutter#192607)
2026-09-12 [email protected] Roll Dart SDK from b24b352c29db to 7863887acbfb (3 revisions) (flutter/flutter#192665)
2026-09-12 [email protected] fix(tree): et format --all (flutter/flutter#192669)
2026-09-12 [email protected] Support activity-alias in Android launcher activity detection (flutter/flutter#187251)
2026-09-12 [email protected] fix: regenerate gradle lockfiles for external_textures integration test (flutter/flutter#192657)
2026-09-12 [email protected] Roll Skia from 51aa02b2c195 to e5e96533b732 (4 revisions) (flutter/flutter#192646)
2026-09-12 [email protected] [WebParagraph] Fix text pixelation, glyph clipping, and snapping offsets to avoid subpixel raster caching (flutter/flutter#191736)
2026-09-12 [email protected] fix(tests): Add ruby dep to Mac windowing_test (flutter/flutter#192656)
2026-09-12 [email protected] Remove some `unawaited_futures` outdated ignores (flutter/flutter#192026)
2026-09-11 [email protected] Bump Dart to 3.13, reformat, re-enable formatting check (flutter/flutter#192649)
2026-09-11 [email protected] [android] Isolate API-34 high contrast listener in AccessibilityBridge behind Api34Impl (flutter/flutter#192502)
2026-09-11 [email protected] Update style guide for Dart 3.13 (flutter/flutter#192639)
2026-09-11 [email protected] ci(bringups): remove bringup from these tests (flutter/flutter#192637)
2026-09-11 [email protected] Unmark new_gallery_windows_impeller__transition_perf as bringup (flutter/flutter#192633)
2026-09-11 [email protected] Unmark new_gallery_windows_skia__transition_perf as bringup (flutter/flutter#192635)
2026-09-11 [email protected] Roll Skia from f446aec4ce9e to 51aa02b2c195 (2 revisions) (flutter/flutter#192631)
2026-09-11 [email protected] fix(ci): mac verify binaries still racing (flutter/flutter#192634)
2026-09-11 [email protected] Roll Packages from 8a35b16 to 9caa77c (8 revisions) (flutter/flutter#192630)
2026-09-11 [email protected] Roll Dart SDK from a76fee2722e0 to b24b352c29db (2 revisions) (flutter/flutter#192627)
2026-09-11 [email protected] [tool] Migrate PackagesCommand and Pub to modular dependency injection (flutter/flutter#192460)
2026-09-11 [email protected] [tool] Migrate Darwin framework commands to modular dependency injection (flutter/flutter#192252)
2026-09-11 [email protected] [tool] Migrate Upgrade, Downgrade, and UpdatePackages commands to modular dependency injection (flutter/flutter#190787)
2026-09-11 [email protected] Roll Skia from b3fa80a0e168 to f446aec4ce9e (55 revisions) (flutter/flutter#192620)
2026-09-11 [email protected] Roll Dart SDK from d20d59cfa664 to a76fee2722e0 (2 revisions) (flutter/flutter#192616)
2026-09-11 [email protected] remove deeplink integration tests from bringup (flutter/flutter#192459)
2026-09-11 [email protected] Revert: [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter/flutter#192615)
2026-09-11 [email protected] Roll Fuchsia Linux SDK from C0j8F-_Iy-OQZ6YyI... to m69nfK-wnHaMTe8P9... (flutter/flutter#192608)
2026-09-11 [email protected] Fix Wasm build cache mismatch in ResidentWebRunner and browser 404 fallbacks (flutter/flutter#190786)
2026-09-11 [email protected] Roll Dart SDK from 3ce3116bc9ec to d20d59cfa664 (1 revision) (flutter/flutter#192588)
2026-09-11 [email protected] [Linux] Keep the frame at the top of a resizing subsurface (flutter/flutter#192408)
2026-09-10 [email protected] [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter/flutter#192584)
2026-09-10 [email protected] [web] Keep ImageSource alive until Picture disposal (flutter/flutter#192516)
2026-09-10 [email protected] Remove the accessibility evaluations feature flag (flutter/flutter#192266)
2026-09-10 [email protected] Promote Windows gradient benchmark tests to non-bringup (flutter/flutter#192581)
2026-09-10 [email protected] Remove commented out export in `text_input.dart` since the dart compiler has the correct behavior now (flutter/flutter#191539)
2026-09-10 [email protected] [flutter_tools] Do not mistake server-initiated requests for responses to client requests in AnalysisServer (flutter/flutter#192546)
2026-09-10 [email protected] Roll Packages from 36e088a to 8a35b16 (12 revisions) (flutter/flutter#192550)
2026-09-10 [email protected] Roll pub packages (flutter/flutter#192517)
2026-09-10 [email protected] feat(web): support --web-content-hash for entrypoint files (flutter/flutter#190153)
2026-09-10 [email protected] [web] Stop iOS auto-zoom by sizing semantic inputs at 16px (flutter/flutter#192328)
2026-09-10 [email protected] Roll Dart SDK from 0d55b7a6a9ee to 3ce3116bc9ec (2 revisions) (flutter/flutter#192534)
2026-09-10 [email protected] Update more enum instances comparison to use equality == since dart has the correct behavior now (flutter/flutter#191788)
2026-09-10 [email protected] Fix specify_nonobvious_local_variable_types lints in luci_resultdb_test.dart (flutter/flutter#192543)
2026-09-10 [email protected] Roll ICU from 8cc91d9b6ab9 to 6ebb40c59477 (1 revision) (flutter/flutter#192527)
2026-09-10 [email protected] [Linux] Make the framebuffer depth/stencil buffer optional (flutter/flutter#192156)
2026-09-10 [email protected] [Linux] Cancel input when events stop being delivered (flutter/flutter#192277)
...
pull Bot pushed a commit to Mu-L/flutter that referenced this pull request Sep 14, 2026
…lutter#192663)

`--web-content-hash` currently hashes only the compiled entrypoints
(flutter#191914). Static assets (flutter#191915), the service worker precache manifest
(flutter#191916), and deferred loading parts (flutter#191917) are all still unhashed,
so
a build with the flag enabled can continue to serve stale cached
content.
Advertising the flag now sets an expectation the implementation does not
yet meet.

The flag has not shipped in any release. It landed on master in flutter#190153
on
2026-09-10, after the flutter-3.48-candidate.0 fork, so hiding it costs
nothing today. It also avoids committing to the flag's boolean shape
before
the remaining phases show whether granularity is needed.

Locks the behavior into the existing `flutter build web option
visibility`
tests, including the verbose-help variant, so the flag stays hidden
rather
than becoming verbose-only by accident.

Un-hide once flutter#191915 and flutter#191916 have landed.
@kevmoo
kevmoo deleted the web-content-hash-phase-1 branch September 22, 2026 05:04
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] Support content-hashed entrypoint filenames (--web-content-hash)

3 participants