Repository navigation
[stable] [flutter_tools] Preserve index.html after --web-content-hash - #196800
auto-submit[bot] merged 1 commit into
Conversation
…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)
|
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. |
There was a problem hiding this comment.
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.
|
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. |
76de0fe
into
flutter:flutter-3.50-candidate.0
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.
Manual cherry-pick of #196491 (
b06753afdde) intoflutter-3.50-candidate.0so runningflutter build webwithout--web-content-hashafter a--web-content-hashbuild no longer deletesbuild/web/index.html.Issue Link:
#196452
Impact Description:
Flutter 3.50.0 introduced
--web-content-hash. In3.50.0,WebTemplatedFilesdeclared{PROJECT_DIR}/web/*/index.htmland{OUTPUT_DIR}/*/index.html, whichSourceVisitor.visitPatternresolved as literal/*/index.htmlpaths instead of registering rootbuild/web/index.htmlin the build output graph (WebReleaseBundleonly registered{OUTPUT_DIR}/index.htmlwhen--web-content-hashwas enabled). When a developer builds with--web-content-hashand then runs a plainflutter build webinto the same output directory,outputSetRemovaldeletes the freshly generatedbuild/web/index.html, producing an unservable deployment directory missingindex.html.This cherry-pick applies #196491 (
b06753afdde), registering rootweb/index.htmlandweb/flutter_bootstrap.jsvia optionalSource.patternentries andweb_templated_files.d, canonicalizing relative/symlinkedoutputDirandprojectDirpaths, and preserving3.50'sserviceWorkerStrategyhandling.Changelog Description:
[flutter/196452] When running
flutter build webwithout--web-content-hashafter a--web-content-hashbuild on web,build/web/index.htmlwas deleted from the build output directory.Workaround:
Run
flutter clean(or deletebuild/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:
flutter build web --web-content-hashon a Flutter web app and confirmbuild/web/index.htmlexists.flutter build web(without--web-content-hash) into the same output directory and confirmbuild/web/index.htmlis preserved and serves the app cleanly.FlutterBuildSystem webContentHash transitionsregression tests inpackages/flutter_tools/test/general.shard/build_system/targets/web_test.dart.