Skip to content

Bundle a local Roboto fallback for no-CDN web builds#184275

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
samanzamani:codex-fix-web-no-cdn-roboto-fallback
May 4, 2026
Merged

Bundle a local Roboto fallback for no-CDN web builds#184275
auto-submit[bot] merged 4 commits into
flutter:masterfrom
samanzamani:codex-fix-web-no-cdn-roboto-fallback

Conversation

@samanzamani

Copy link
Copy Markdown
Contributor

Problem

  • still leaves a runtime request to for Roboto.
  • This breaks Flutter web deployments on private networks with no internet access.

Solution

  • Bundle Flutter's local into the web output when CDN-backed web resources are disabled.
  • Append a entry to the generated when the app did not already provide one.
  • Reuse the existing engine behavior so the web renderer loads the bundled Roboto asset instead of attempting a remote fallback download.

Tests

  • Running build hooks...Running build hooks...00:00 +0: loading test/general.shard/build_system/targets/web_test.dart
    00:00 +0 -1: loading test/general.shard/build_system/targets/web_test.dart [E]
    Failed to load "test/general.shard/build_system/targets/web_test.dart": Does not exist.
    00:00 +0 -1: Some tests failed.

Failing tests:
test/general.shard/build_system/targets/web_test.dart: loading test/general.shard/build_system/targets/web_test.dart

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

google-cla Bot commented Mar 28, 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.

@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 introduces a mechanism to bundle a local Roboto font fallback for web builds when the kUseLocalCanvasKitFlag is enabled. The WebReleaseBundle target was modified to verify the presence of the Roboto font in the FontManifest.json and, if absent, copy the font from the engine source to the assets directory. Review feedback recommends refactoring hardcoded engine font paths into constants in both the implementation and test files to enhance maintainability and adhere to readability principles.

Comment on lines +692 to +703
final File sourceRobotoFont = environment.fileSystem.file(
environment.fileSystem.path.join(
Cache.flutterRoot!,
'engine',
'src',
'flutter',
'txt',
'third_party',
'fonts',
'Roboto-Regular.ttf',
),
);

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.

medium

The path to the Roboto font is constructed from multiple hardcoded string literals. This is brittle and can lead to breakage if the engine's internal directory structure changes. It also impacts readability.

To improve maintainability and align with the style guide's principle to "Optimize for readability", I recommend extracting this path into a private, top-level constant. This provides a single source of truth for the path and makes the code easier to understand and update.

Here's how you could refactor it:

  1. Add a constant at the top of the file:

    const String _kEngineRobotoFontPath = 'engine/src/flutter/txt/third_party/fonts/Roboto-Regular.ttf';
  2. Use this constant in the _bundleLocalRobotoFallback method:

    final File sourceRobotoFont = environment.fileSystem.file(
      environment.fileSystem.path.join(
        Cache.flutterRoot!,
        _kEngineRobotoFontPath,
      ),
    );

This change will make the dependency on this specific engine file more explicit and easier to manage in the future.

References
  1. Optimize for readability: Code is read more often than it is written. (link)

@bkonyi bkonyi added the team-web Owned by Web platform team label Apr 13, 2026
@bkonyi bkonyi requested review from bkonyi and mdebbar April 13, 2026 15:40
@bkonyi

bkonyi commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution @samanzamani! It look like you'll need to sign the CLA before this can be submitted. Is there an issue filed that this PR is addressing?

I don't have any serious concerns with this change, but I'd like to check in with the team to make sure this is the right way to handle this case. We might want to put this behavior behind a flag instead, or this might just be working as intended with the solution being to manually add the font to the manifest explicitly. I'm personally not too familiar with the default set of fonts, so I'm also not sure if limiting this to Roboto is sufficient.

cc @mdebbar for input on the PR and @justinmc for confirmation on the set of "default" fonts.

Comment thread packages/flutter_tools/lib/src/build_system/targets/web.dart Outdated
@github-actions github-actions Bot removed the team-web Owned by Web platform team label Apr 13, 2026
@samanzamani samanzamani force-pushed the codex-fix-web-no-cdn-roboto-fallback branch from 90b99db to 9dfd709 Compare April 13, 2026 16:45
@samanzamani

samanzamani commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

Hi @bkonyi , thanks for the review.

Regarding the CLA — my first commit was authored with a local machine email instead of my GitHub-associated email. I've just rebased and amended both commits with the correct email and force-pushed. The CLA check should pass now.

As for the PR itself — there isn't a specific issue filed for this. I noticed that when using --web-resources-cdn flag with local CanvasKit, the Roboto fallback font wasn't being bundled if it wasn't already in the font manifest. This caused missing font issues in offline/no-CDN web builds.

@mdebbar mdebbar added the CICD Run CI/CD label Apr 17, 2026

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

Looks good to me!

We've always wanted to do this for Roboto and fallback fonts on the web, so this change is welcome!

To answer @bkonyi's question, yes, Roboto is the only font that we download by default on the web. We download fallback fonts for non-Latin languages, but that happens on-demand. Starting with Roboto being available offline is a good step forward. Thank you for the contribution @samanzamani !

You need to rebase to resolve the ci.yaml validation error.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 17, 2026
bkonyi
bkonyi previously approved these changes Apr 17, 2026

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

Thanks for confirming @mdebbar!

This LGTM!

@bkonyi bkonyi added the CICD Run CI/CD label Apr 17, 2026
@bkonyi

bkonyi commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Hi @samanzamani! It looks like there's some analysis errors that are going to block this from being merged.

@samanzamani samanzamani force-pushed the codex-fix-web-no-cdn-roboto-fallback branch from 3c30892 to e9ab31c Compare April 22, 2026 05:41
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 22, 2026
@samanzamani

Copy link
Copy Markdown
Contributor Author

Hi @bkonyi . I rebased this PR onto the latest upstream master, resolved the merge conflict, and fixed the flutter_tools analysis lints that were blocking it.

@bkonyi bkonyi added the CICD Run CI/CD label Apr 22, 2026
@bkonyi bkonyi requested a review from mdebbar April 22, 2026 17:29
@bkonyi

bkonyi commented May 4, 2026

Copy link
Copy Markdown
Contributor

@mdebbar can I get you to reapprove this?

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label May 4, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 4, 2026
@auto-submit

auto-submit Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/184275, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@github-actions github-actions Bot removed the CICD Run CI/CD label May 4, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label May 4, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 4, 2026
@auto-submit

auto-submit Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/184275, Failed to enqueue flutter/flutter/184275 with HTTP 400: Pull request Required status check "Merge Queue Guard" is expected..

@bkonyi

bkonyi commented May 11, 2026

Copy link
Copy Markdown
Contributor

Hey @bkonyi, heads up this increased the size 170k

Is this something we're particularly concerned about @mdebbar? I think this is a fairly minor regression for fix for an important fallback case.

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.

4 participants