Sitelet https://github.com/flutter/flutter/pull/189622
Skip to content

Pass web-defines to the web builder in all run configurations - #189622

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
matheusccastroo:fix-web-define-profile-release
Aug 7, 2026
Merged

auto-submit[bot] merged 4 commits into
flutter:masterfrom
matheusccastroo:fix-web-define-profile-release

Conversation

@matheusccastroo

@matheusccastroo matheusccastroo commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

--web-define substitution of {{PLACEHOLDER}} tokens in web/index.html and
flutter_bootstrap.js worked in debug flutter run (serve-time substitution in
WebAssetServer) and in flutter build web (webDefine:-prefixed entries in the
build Environment consumed by the WebTemplatedFiles target), but not in
flutter run --profile or --release: ResidentWebRunner stored the parsed
defines in _webDefines and then omitted them from both WebBuilder.buildWeb()
calls in the non-debug branch, and ReleaseAssetServer serves the build output
verbatim with no serve-time templating, so the placeholders were never replaced.

This passes webDefines to both buildWeb() call sites (the initial build in
run() and the rebuild on hot restart), matching how flutter build web already
passes them. Debug --wasm runs take the same branch and are fixed as a side
effect. flutter drive never forwarded web-defines in any mode, so the flag is
now plumbed through DriverService.start() into WebDriverService and on to the
web runner.

Added unit tests assert that the build Environment receives the
webDefine:-prefixed defines in profile mode, on the rebuild after a hot restart
in release mode, and in debug --wasm mode; that WebDriverService forwards
web-defines to the web runner; and that the drive command forwards --web-define
values to DriverService.start().

Added end-to-end tests run the real tool against a fixture project whose
web/index.html and web/flutter_bootstrap.js contain {{MY_VERSION}} and
{{API_URL}} placeholders: flutter build web in debug/profile/release must
substitute them in build/web/index.html and build/web/flutter_bootstrap.js,
and flutter run -d web-server in debug/profile/release must serve substituted
HTML, including after hot reload (debug) and hot restart (all three modes).
Existing web-define coverage for flutter build web and debug-mode serving is
unchanged and passing.

Fixes #8885 (was closed, but the problem was actually this - the flag was only passed on specific run configurations). Also related to PR #175805 and issue #127853

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 16, 2026
@google-cla

google-cla Bot commented Jul 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@matheusccastroo matheusccastroo changed the title Pass web-defines to the web builder in flutter run profile and releas… Pass web-defines to the web builder in all run configurations Jul 16, 2026
@matheusccastroo
matheusccastroo force-pushed the fix-web-define-profile-release branch 2 times, most recently from 1989db4 to 6241e70 Compare July 17, 2026 20:52
@matheusccastroo
matheusccastroo marked this pull request as ready for review July 17, 2026 20:54
@matheusccastroo

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 adds support for forwarding and substituting --web-define values during flutter drive and flutter run commands for web targets. It updates DriveCommand, DriverService, WebDriverService, and ResidentWebRunner to accept and propagate webDefines. Additionally, new unit, integration, and web shard tests are introduced to verify that --web-define placeholders are correctly substituted in the output and served files, and that this substitution persists across hot reloads and hot restarts. There are no review comments, and I have no feedback to provide.

@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 adds support for forwarding --web-define flags to the web runner during flutter drive and flutter run commands, ensuring placeholders are correctly substituted in index.html and flutter_bootstrap.js. Feedback suggests scoping the buildEnvironment variable inside a test group in resident_web_runner_test.dart to avoid state leakage, and relaxing the SDK constraint in the test project's pubspec to improve compatibility.

Comment thread packages/flutter_tools/test/general.shard/resident_web_runner_test.dart Outdated
…e modes and to flutter drive

--web-define substitution of {{PLACEHOLDER}} tokens in web/index.html and
flutter_bootstrap.js worked in debug flutter run (serve-time substitution in
WebAssetServer) and in flutter build web (webDefine:-prefixed entries in the
build Environment consumed by WebTemplatedFiles), but not in flutter run
--profile or --release: ResidentWebRunner stored the parsed defines in
_webDefines and then omitted them from both WebBuilder.buildWeb() calls in
the non-debug branch, and ReleaseAssetServer serves the build output verbatim
with no serve-time templating, so the placeholders were never replaced.

This passes webDefines to both buildWeb() call sites (the initial build in
run() and the rebuild on hot restart), matching how flutter build web already
passes them. Debug --wasm runs take the same branch and are fixed as a side
effect. flutter drive never forwarded web-defines in any mode, so the flag is
now plumbed through DriverService.start() into WebDriverService and on to the
web runner.

## Tests

Added tests asserting the build Environment receives the webDefine:-prefixed
defines in profile mode, on the rebuild after a hot restart in release mode,
and in debug --wasm mode; that WebDriverService forwards web-defines to the
web runner; and that the drive command forwards --web-define values to
DriverService.start(). Existing web-define coverage for flutter build web and
debug-mode serving is unchanged and passing.
@matheusccastroo
matheusccastroo force-pushed the fix-web-define-profile-release branch from 08383a7 to a8c93db Compare July 17, 2026 21:20
@matheusccastroo

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 adds support for forwarding --web-define arguments to the web runner during flutter drive and flutter run commands, updating the driver services and runner configurations accordingly. It also introduces integration and unit tests to verify that placeholders are correctly substituted in the output files and maintained across hot restarts and reloads. The review feedback suggests simplifying the test project's continuous loop to prevent high CPU usage, wrapping the test driver teardown in a try-finally block to ensure temporary directory cleanup, and adding a connection timeout to the HTTP client to prevent test hangs.

Comment thread packages/flutter_tools/test/web.shard/web_define_run_test.dart
Comment thread packages/flutter_tools/test/web.shard/web_define_run_test.dart
@bkonyi
bkonyi requested review from bkonyi and chingjun August 5, 2026 15:08
@bkonyi bkonyi added the CICD Run CI/CD label Aug 5, 2026

expect(await residentWebRunner.run(), 0);
expect(buildEnvironment, isNotNull);
expect(buildEnvironment!.defines['webDefine:VERSION'], 'v1.2.3');

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.

We can just perform this check in the callback below instead of setting buildEnvironment here and in other test cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bkonyi fixed, now we do the assertions in the callback for all the new tests.

chingjun
chingjun previously approved these changes Aug 5, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 5, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 5, 2026
@auto-submit

auto-submit Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/189622, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@matheusccastroo

Copy link
Copy Markdown
Contributor Author

@bkonyi @chingjun please review again 😄

@bkonyi bkonyi added the CICD Run CI/CD label Aug 6, 2026
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.

3 participants