Skip to content

feat: Add --base-href support to flutter run for web#182709

Merged
auto-submit[bot] merged 10 commits intoflutter:masterfrom
Mastersam07:add-base-href-to-run-command
Mar 24, 2026
Merged

feat: Add --base-href support to flutter run for web#182709
auto-submit[bot] merged 10 commits intoflutter:masterfrom
Mastersam07:add-base-href-to-run-command

Conversation

@Mastersam07
Copy link
Contributor

@Mastersam07 Mastersam07 commented Feb 21, 2026

Description

Adds --base-href support to the flutter run command for web targets.

Previously, --base-href was only available on flutter build web, which meant developers testing web apps hosted in subfolders had to manually edit web/index.html during development and undo the change before committing. This PR brings the same flag to flutter run, so the dev server correctly serves the app with a custom base path.

Usage

flutter run -d chrome --base-href=/preview/

The value must start and end with /, matching the same validation as flutter build web --base-href.

Fixes #163141

Pre-launch Checklist

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 21, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 the --base-href flag to the flutter run command for web targets, which is a valuable addition for developers testing applications in subfolders. The implementation correctly handles template substitution and server routing. I've noted a few improvements: ensuring the value is also read from the configuration file, adding the missing parsing logic in WebDevServerConfig.fromYaml, and using existing utility functions for cleaner string manipulation.

@bkonyi bkonyi added the team-web Owned by Web platform team label Feb 24, 2026
@bkonyi bkonyi requested a review from mdebbar February 24, 2026 15:28
bkonyi
bkonyi previously approved these changes Feb 24, 2026
Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

LGTM once a couple of comments are addressed.

'base-href',
help:
'Overrides the href attribute of the <base> tag in web/index.html. '
'No change is done to web/index.html file if this flag is not provided. '
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "No change is made to web/index.html"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b94d5a5

help:
'Overrides the href attribute of the <base> tag in web/index.html. '
'No change is done to web/index.html file if this flag is not provided. '
'The value has to start and end with a slash "/". '
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: 'This value must start and end with "/". '

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b94d5a5

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

LGTM with a suggestion to deduplicate the flag between run and build.

Comment on lines +407 to +414
argParser.addOption(
'base-href',
help:
'Overrides the href attribute of the <base> tag in web/index.html. '
'No change is done to web/index.html file if this flag is not provided. '
'The value has to start and end with a slash "/". '
'For more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base',
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs its own usesWebBaseHrefFlag() that is shared between run and build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, since --base-href flag is duplicated; defined separately across both

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 3e2148e

@Piinks Piinks added platform-web Web applications specifically and removed team-web Owned by Web platform team labels Mar 2, 2026
@github-actions github-actions bot removed the platform-web Web applications specifically label Mar 12, 2026
mdebbar
mdebbar previously approved these changes Mar 13, 2026
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

LGTM

@mdebbar mdebbar requested a review from bkonyi March 13, 2026 14:55
@mdebbar mdebbar added the CICD Run CI/CD label Mar 13, 2026
@mdebbar mdebbar added CICD Run CI/CD and removed CICD Run CI/CD labels Mar 13, 2026
bkonyi
bkonyi previously approved these changes Mar 13, 2026
@mdebbar
Copy link
Contributor

mdebbar commented Mar 16, 2026

As reported in this failure, some files need to be dart-formatted:

dart format packages/flutter_tools/test/general.shard/web/web_asset_server_test.dart packages/flutter_tools/test/commands.shard/hermetic/run_test.dart

@Mastersam07 Mastersam07 dismissed stale reviews from bkonyi and mdebbar via 4c4d151 March 16, 2026 14:40
@Mastersam07
Copy link
Contributor Author

Applied the formatting in 4c4d151

@mdebbar @bkonyi

@Mastersam07 Mastersam07 requested a review from mdebbar March 16, 2026 16:52
@Mastersam07 Mastersam07 requested a review from bkonyi March 16, 2026 16:52
@github-actions github-actions bot removed the CICD Run CI/CD label Mar 24, 2026
Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

@mdebbar can you reapprove?

@mdebbar mdebbar added the CICD Run CI/CD label Mar 24, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 24, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Mar 24, 2026
Merged via the queue into flutter:master with commit 1ff4012 Mar 24, 2026
151 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 25, 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.

[Proposal] Support --base-href for flutter run

4 participants