Skip to content

[stable] [flutter_tools] Preserve index.html after --web-content-hash - #196800

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.50-candidate.0from
kevmoo:cp-3.50-issue-196452
Nov 18, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:flutter-3.50-candidate.0from
kevmoo:cp-3.50-issue-196452

Conversation

@kevmoo

@kevmoo kevmoo commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

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.

…ions (flutter#196491)

Fixes flutter#196452 by registering
root templated `index.html` outputs in the build graph and
canonicalizing symlinked and relative output paths so switching off
`--web-content-hash` never deletes freshly generated `index.html`.

- Replaces literal `{PROJECT_DIR}/web/*/index.html` and
`{OUTPUT_DIR}/*/index.html` patterns (`SourceVisitor.visitPattern`
expands `*` only in the final filename segment) with optional
`{PROJECT_DIR}/web/index.html`,
`{PROJECT_DIR}/web/flutter_bootstrap.js`, `{OUTPUT_DIR}/index.html`, and
`web_templated_files.d` (deleting stale `outputDir/index.html` when
`web/index.html` is absent), templating only root `web/index.html` while
keeping nested `web/sub/index.html` files as plain static resource
copies.
- Canonicalizes `outputDir` and `projectDir` via
`resolveSymbolicLinksSync()` across `WebTemplatedFiles`,
`WebReleaseBundle`, and `WebServiceWorker` so relative `-o` and
symlinked output directories (such as macOS `/tmp -> /private/tmp`)
match `Source.pattern` keys across flag transitions and template edits.
- Scoped strictly to `WebTemplatedFiles`, `WebReleaseBundle`, and
`WebServiceWorker` so this fix cherry-picks cleanly onto `3.50`
(`WebCompiledArtifact` and compiler output tracking updates moved to
follow-up flutter#196563).

- [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

(cherry picked from commit b06753a)
@kevmoo kevmoo added tool Affects the "flutter" command-line tool. See also t: labels. cp: review Cherry-picks in the review queue CICD Run CI/CD labels Nov 17, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@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 targets in the Flutter build system to resolve symbolic links for project and output directories, and to support optional template files like index.html and flutter_bootstrap.js. It introduces a helper function _resolveDirectory to handle symlink resolution, updates the dependency tracking for templated files by writing a web_templated_files.d depfile, and ensures that resource copying and service worker generation handle missing directories gracefully. Additionally, a comprehensive suite of unit tests has been added to verify transitions between hashed and plain web builds, including scenarios with relative paths and symlinks. I have no feedback to provide as there are no review comments.

@kevmoo
kevmoo requested a review from mdebbar November 17, 2026 17:48

@justinmc justinmc 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.

LGTM 👍

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit

auto-submit Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196800, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

@kevmoo kevmoo added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit
auto-submit Bot merged commit 76de0fe into flutter:flutter-3.50-candidate.0 Nov 18, 2026
5 checks passed
@kevmoo
kevmoo deleted the cp-3.50-issue-196452 branch November 18, 2026 18:46
@victorsanni victorsanni mentioned this pull request Nov 18, 2026
11 tasks done
auto-submit Bot pushed a commit that referenced this pull request Nov 19, 2026
Adds `CHANGELOG.md` entries for the 3.50.1 stable hotfix (#196756, #196721, #196127, #196035, #196418, #196800, #196796, #196895, #196383, #196923). Omits the infra-only #196760 and the `engine.version` sync #196932.

Tracker: #196743

### Edits to cherry-pick changelog descriptions
- All entries use the cherry-pick PR's "Changelog Description" verbatim, except for backticks around code terms (#196756, #196418, #196895, #196923) and a comma and trailing period in the #196418 entry.
- #196923 also cherry-picks #195006, so it has two entries, as listed in its "Changelog Description".

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants