Repository navigation
[flutter_tools] Preserve index.html across --web-content-hash transitions - #196491
Conversation
`SourceVisitor.visitPattern` only expands `*` in the final path segment, so
`WebTemplatedFiles` resolved `{PROJECT_DIR}/web/*/index.html` and
`{OUTPUT_DIR}/*/index.html` to literal `/*/index.html` paths instead of
`index.html`. When switching from `--web-content-hash` to a plain
`flutter build web`, `WebReleaseBundle` dropped `{OUTPUT_DIR}/index.html`
from its outputs (`outputSetRemoval`) and `_deleteStaleOutputs` deleted
`build/web/index.html` because `WebTemplatedFiles` had not registered it in
the shared `outputFiles` graph.
- Declare `{OUTPUT_DIR}/index.html` (optional) on `WebTemplatedFiles.outputs`,
track templated inputs and outputs via `web_templated_files.d` (shared with
`WebReleaseBundle` under `--web-content-hash`), and canonicalize
`outputDir` / `projectDir` via `resolveSymbolicLinksSync()` across
`WebTemplatedFiles`, `WebReleaseBundle`, and `WebServiceWorker` so relative
`-o` and symlinked output/project paths match `Source.pattern` keys across
plain<->hashed transitions and incremental template edits.
- Keep `recorded_uses_js.json`, `recorded_uses_wasm.json`, and
`main.dart.support.js` scoped to `{BUILD_DIR}` compiler target outputs
(excluding `main.dart.support.js` from `Dart2JSTarget`'s `main.dart.*.js`
glob and marking optional `main.dart.mjs.map` / web recorded-uses inputs)
so consecutive plain, `--web-content-hash`, `--wasm`, and `--source-maps`
builds skip cleanly without deleting `main.dart.support.js`.
Fixes flutter#196452
There was a problem hiding this comment.
Code Review
This pull request refactors the Flutter web build system targets to improve directory resolution, stale output cleanup, and the management of recorded uses and metadata files across compiler transitions. The review feedback identifies an issue where the _entrypointFileRegex in WebReleaseBundle does not match main.dart.support.js, leaving it behind as a stale artifact when transitioning from WebAssembly to plain JavaScript builds, and provides a code suggestion to resolve this.
Introduce `WebCompiledArtifact` using `basename.split('.')` list-pattern
matching and exhaustive JS/Wasm classification getters across
`Dart2JSTarget`, `Dart2WasmTarget`, and `WebReleaseBundle`.
mdebbar
left a comment
There was a problem hiding this comment.
Since #196452 ships a site without index.html on 3.50 stable, should we keep this PR to just the index.html fix (WebTemplatedFiles outputs/depfile + path canonicalization) so it's easy to cherry-pick? The WebCompiledArtifact refactor and the other tracking fixes could go in a follow-up PR.
Template only root web/index.html (preserving static copies for nested index.html files without web_templated_files.d) and move WebCompiledArtifact and compiler output tracking updates to a follow-up branch so this fix cherry-picks cleanly onto 3.50.
|
Good call — narrowed this PR in 0a81827 strictly to the root index.html output tracking and path canonicalization fix so it cherry-picks cleanly to 3.50, and staged WebCompiledArtifact + the compiler tracking fixes (with your review suggestions) for a follow-up PR. |
mdebbar
left a comment
There was a problem hiding this comment.
Thanks for splitting this up!
…er paths - Add web_templated_files.d to WebTemplatedFiles and delete stale outputDir/index.html when web/index.html is absent. - Resolve webResources once in WebTemplatedFiles.build and canonicalize userServiceWorker and serviceWorkerFile paths in WebServiceWorker.build. - Remove redundant writeEmpty: true on flutter_assets.d and add regression tests for template deletion and symlinked custom service workers.
…59) Fixes the `p.canonicalize` symlink claim in `dart-use-path-package` and adds a compound-filename list-pattern classification example to `dart-use-pattern-matching`. - **Lexical `p.canonicalize` vs. physical symlinks**: [`skills/dart-use-path-package/SKILL.md`](https://github.com/dart-lang/skills/blob/fa691671fda391ea1d1f8c7ae61bddc03348ec85/skills/dart-use-path-package/SKILL.md#L37-L40) directed physical symlink identity checks to `p.canonicalize(path)`, which is purely lexical (`package:path` does not resolve symlinks). Directs physical path comparisons and cache keys (e.g., macOS `/tmp` -> `/private/tmp` or relative `-o` directories in [flutter/flutter#196491](flutter/flutter#196491)) to `resolveSymbolicLinksSync()`. - **Multi-dot filename classification without `RegExp`**: Adds an executable `BuildArtifact.tryParse` example (`switch (name.split('.'))` with `...` rest matching and an inline `when int.tryParse(part) != null` guard) showing how to classify compound build artifacts without wildcard/regex over-matching (such as `main.dart.*.js` swallowing `main.dart.support.js` in [flutter/flutter#196452](flutter/flutter#196452)).
|
autosubmit label was removed for flutter/flutter/196491, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@d8bd864...2f09f96 2026-11-17 [email protected] Analyze every flutter create template, and fix the package_ffi lint (flutter/flutter#196165) 2026-11-17 [email protected] Roll Dart SDK from 50debf3c9757 to 26e38955d9d4 (3 revisions) (flutter/flutter#196772) 2026-11-17 [email protected] Manual roll ICU from b09986242cfb to d3c612f44146 (1 revision) (flutter/flutter#196713) 2026-11-17 [email protected] Roll Skia from 4f6b3a8d8565 to 503a380ebecc (19 revisions) (flutter/flutter#196768) 2026-11-17 [email protected] iOS: Don't mock UIView animations in keyboard spring animation test (flutter/flutter#196755) 2026-11-17 [email protected] [flutter_tools] Preserve index.html across --web-content-hash transitions (flutter/flutter#196491) 2026-11-17 [email protected] Fix TextStyle background color fade-out when lerping to null (flutter/flutter#196153) 2026-11-17 [email protected] Update desktop engine TESTOWNERS (flutter/flutter#196732) 2026-11-17 [email protected] [flutter_tools] Do not copy app-only build type properties onto library plugins (flutter/flutter#196692) 2026-11-17 [email protected] [flutter_tools] Remove service and runner ambient context getters (flutter/flutter#196571) 2026-11-17 [email protected] Bump customer tests (flutter/flutter#196740) 2026-11-17 [email protected] Take customer_testing_flame out of bringup (flutter/flutter#196570) 2026-11-17 [email protected] [devicelab] Read AssetManifest.bin from the APK in flavors_test (flutter/flutter#196736) 2026-11-17 [email protected] [flutter_tools] Fix flaky tool_tests_general by moving spawnUri tests to integration shard (flutter/flutter#195999) 2026-11-17 [email protected] Roll Dart SDK from 3e069c6fdbde to 50debf3c9757 (2 revisions) (flutter/flutter#196706) 2026-11-16 [email protected] [web] Record build finish synchronously in renderScene and fix dropped frame timings (flutter/flutter#195947) 2026-11-16 [email protected] Do not reveal obscured character when input is rejected by inputFormatters (flutter/flutter#195022) 2026-11-16 [email protected] Cla draft follow up: add waiting for response (flutter/flutter#196686) 2026-11-16 [email protected] Roll pub packages (flutter/flutter#196684) 2026-11-16 [email protected] Roll Packages from 015df97 to 4c6a7d3 (8 revisions) (flutter/flutter#196681) 2026-11-16 [email protected] Skip Vulkan impeller_unittests on macOS (flutter/flutter#196282) 2026-11-16 [email protected] Move the task runners out of Flutter Engine (flutter/flutter#196267) 2026-11-16 [email protected] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… (flutter/flutter#196465) 2026-11-16 [email protected] iOS: Add Obj-C model for platform view composition params (flutter/flutter#196498) 2026-11-16 [email protected] [Windows] Normalize Shift key messages with a non-standard scan code (flutter/flutter#193675) 2026-11-16 [email protected] Roll Skia from 118eaff3deb4 to 4f6b3a8d8565 (3 revisions) (flutter/flutter#196672) 2026-11-16 [email protected] Roll Dart SDK from c91e8b6674e2 to 3e069c6fdbde (4 revisions) (flutter/flutter#196669) 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
…#196800) Manual cherry-pick of #196491 (`b06753afdde`) into `flutter-3.50-candidate.0` so running `flutter build web` without `--web-content-hash` after a `--web-content-hash` build no longer deletes `build/web/index.html`. ### Issue Link: #196452 ### Impact Description: Flutter 3.50.0 introduced `--web-content-hash`. In `3.50.0`, `WebTemplatedFiles` declared `{PROJECT_DIR}/web/*/index.html` and `{OUTPUT_DIR}/*/index.html`, which `SourceVisitor.visitPattern` resolved as literal `/*/index.html` paths instead of registering root `build/web/index.html` in the build output graph (`WebReleaseBundle` only registered `{OUTPUT_DIR}/index.html` when `--web-content-hash` was enabled). When a developer builds with `--web-content-hash` and then runs a plain `flutter build web` into the same output directory, `outputSetRemoval` deletes the freshly generated `build/web/index.html`, producing an unservable deployment directory missing `index.html`. This cherry-pick applies #196491 (`b06753afdde`), registering root `web/index.html` and `web/flutter_bootstrap.js` via optional `Source.pattern` entries and `web_templated_files.d`, canonicalizing relative/symlinked `outputDir` and `projectDir` paths, and preserving `3.50`'s `serviceWorkerStrategy` handling. ### Changelog Description: [flutter/196452] When running `flutter build web` without `--web-content-hash` after a `--web-content-hash` build on web, `build/web/index.html` was deleted from the build output directory. ### Workaround: Run `flutter clean` (or delete `build/web/` and `.dart_tool/flutter_build/`) before building without `--web-content-hash`. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: 1. Run `flutter build web --web-content-hash` on a Flutter web app and confirm `build/web/index.html` exists. 2. Run `flutter build web` (without `--web-content-hash`) into the same output directory and confirm `build/web/index.html` is preserved and serves the app cleanly. 3. Covered by 8 `FlutterBuildSystem webContentHash transitions` regression tests in `packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart`.
… (#196800) Manual cherry-pick of flutter/flutter#196491 (`b06753afdde`) into `flutter-3.50-candidate.0` so running `flutter build web` without `--web-content-hash` after a `--web-content-hash` build no longer deletes `build/web/index.html`. ### Issue Link: flutter/flutter#196452 ### Impact Description: Flutter 3.50.0 introduced `--web-content-hash`. In `3.50.0`, `WebTemplatedFiles` declared `{PROJECT_DIR}/web/*/index.html` and `{OUTPUT_DIR}/*/index.html`, which `SourceVisitor.visitPattern` resolved as literal `/*/index.html` paths instead of registering root `build/web/index.html` in the build output graph (`WebReleaseBundle` only registered `{OUTPUT_DIR}/index.html` when `--web-content-hash` was enabled). When a developer builds with `--web-content-hash` and then runs a plain `flutter build web` into the same output directory, `outputSetRemoval` deletes the freshly generated `build/web/index.html`, producing an unservable deployment directory missing `index.html`. This cherry-pick applies flutter/flutter#196491 (`b06753afdde`), registering root `web/index.html` and `web/flutter_bootstrap.js` via optional `Source.pattern` entries and `web_templated_files.d`, canonicalizing relative/symlinked `outputDir` and `projectDir` paths, and preserving `3.50`'s `serviceWorkerStrategy` handling. ### Changelog Description: [flutter/196452] When running `flutter build web` without `--web-content-hash` after a `--web-content-hash` build on web, `build/web/index.html` was deleted from the build output directory. ### Workaround: Run `flutter clean` (or delete `build/web/` and `.dart_tool/flutter_build/`) before building without `--web-content-hash`. ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: 1. Run `flutter build web --web-content-hash` on a Flutter web app and confirm `build/web/index.html` exists. 2. Run `flutter build web` (without `--web-content-hash`) into the same output directory and confirm `build/web/index.html` is preserved and serves the app cleanly. 3. Covered by 8 `FlutterBuildSystem webContentHash transitions` regression tests in `packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart`.
…er#196563) Fixes perpetual rebuilds and stale artifact leaks across consecutive `flutter build web`, `--wasm`, `--source-maps`, and `--web-content-hash` transitions, exposes resolved directory getters on `Environment` in `build_system.dart`, and replaces compiler filename regexes with `WebCompiledArtifact` list-pattern matching (follow-up to flutter#196491; part of flutter#149031). - Adds `resolvedProjectDir` and `resolvedOutputDir` getters on `Environment` (resolving symlinks and relative paths without mutating raw `projectDir`/`outputDir`), replacing per-target `_resolveDirectory` helpers in `web.dart` and updating `_deleteStaleOutputs`. - Scopes `recorded_uses_js.json`, `recorded_uses_wasm.json`, and `{BUILD_DIR}/main.dart.support.js` (`Dart2WasmTarget.supportJsFileName`) to active `{BUILD_DIR}` compiler targets (passing and keying active `recordedUsesFileNames` across `LinkHooks`, `WebReleaseBundle`, and `copyAssets`/`IconTreeShaker`, cleaning stale Wasm outputs and `dart2wasm.d` on dry runs, excluding `{BUILD_DIR}/main.dart.support.js` from `Dart2JSTarget.resolveOutputs`, `WebReleaseBundle.resolveInputs`, and non-Wasm `WebTemplatedFiles.resolveInputs` without dropping user `web/**` files, and dropping non-existent `main.dart.mjs.map` tracking) so unchanged non-dry-run and bundle targets skip cleanly without deleting `_flutter.supportsDart2Wasm`. - Strips absent `assetManifest`, `fontManifest`, and `extraAssets` keys in `injectManifestBuildConfig` (including when all three become absent) when re-injecting `_flutter.buildConfig`. - Replaces the compiler and bundle filename `RegExp` fields in `web.dart` with `WebCompiledArtifact` (`basename.split('.')` Dart 3 list patterns). ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
* Enable S16 flag-toggle scenario in wasm_e2e CI - Run redteam_harness S16 against sim and firebase-emulator backends in wasm_e2e now that flutter/flutter#196491 has landed on Flutter master. * Key Flutter master SDK cache in wasm_e2e on upstream HEAD SHA - Resolve `flutter/flutter` `refs/heads/master` SHA and pass it to `subosito/flutter-action` `cache-key` so `wasm_e2e` invalidates cached SDKs when new commits land on Flutter `master`.
Fixes #196452 by registering root templated
index.htmloutputs in the build graph and canonicalizing symlinked and relative output paths so switching off--web-content-hashnever deletes freshly generatedindex.html.{PROJECT_DIR}/web/*/index.htmland{OUTPUT_DIR}/*/index.htmlpatterns (SourceVisitor.visitPatternexpands*only in the final filename segment) with optional{PROJECT_DIR}/web/index.html,{PROJECT_DIR}/web/flutter_bootstrap.js,{OUTPUT_DIR}/index.html, andweb_templated_files.d(deleting staleoutputDir/index.htmlwhenweb/index.htmlis absent), templating only rootweb/index.htmlwhile keeping nestedweb/sub/index.htmlfiles as plain static resource copies.outputDirandprojectDirviaresolveSymbolicLinksSync()acrossWebTemplatedFiles,WebReleaseBundle, andWebServiceWorkerso relative-oand symlinked output directories (such as macOS/tmp -> /private/tmp) matchSource.patternkeys across flag transitions and template edits.WebTemplatedFiles,WebReleaseBundle, andWebServiceWorkerso this fix cherry-picks cleanly onto3.50(WebCompiledArtifactand compiler output tracking updates moved to follow-up [flutter_tools] Fix web compiler output tracking in web builds #196563).Pre-launch Checklist
///).