Skip to content

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

Open
samanzamani wants to merge 1 commit intoflutter:masterfrom
samanzamani:codex-fix-web-no-cdn-roboto-fallback
Open

Bundle a local Roboto fallback for no-CDN web builds#184275
samanzamani wants to merge 1 commit intoflutter:masterfrom
samanzamani:codex-fix-web-no-cdn-roboto-fallback

Conversation

@samanzamani
Copy link
Copy Markdown

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
Copy link
Copy Markdown

google-cla bot commented Mar 28, 2026

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.

Copy link
Copy Markdown
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 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)

Comment on lines +81 to +83
globals.fs
.file('engine/src/flutter/txt/third_party/fonts/Roboto-Regular.ttf')
.createSync(recursive: true);
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

Similar to the implementation file, the path to the mock Roboto font is hardcoded here. This makes the test dependent on a magic string that mirrors the implementation.

For better maintainability and readability, you could extract this path into a constant within the test file. This would make the test easier to read and update if the source path changes.

Example:

const String _kEngineRobotoFontPathForTest = 'engine/src/flutter/txt/third_party/fonts/Roboto-Regular.ttf';

// in setUp
globals.fs
    .file(_kEngineRobotoFontPathForTest)
    .createSync(recursive: true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant