Skip to content

Conversation

@andrewkolos
Copy link
Contributor

@andrewkolos andrewkolos commented Jun 2, 2023

Fixes #127090.

#122505 did a few things to speed up the first asset load that a flutter app performs. One of those things was to not include the main asset in its own list of variants in the asset manifest. The idea was that we know that the main asset always exists, so including it in its list of variants is a waste of storage space and loading time (even if the cost was tiny).

However, the assumption that the main asset always exists is wrong. From Declaring resolution-aware image assets, which predates #122505:

Each entry in the asset section of the pubspec.yaml should correspond to a real file, with the exception of the main asset entry. If the main asset entry doesn’t correspond to a real file, then the asset with the lowest resolution is used as the fallback for devices with device pixel ratios below that resolution. The entry should still be included in the pubspec.yaml manifest, however.

For example, it's valid to declare assets/image.png as an asset even if only assets/3x/image.png exists on disk.

This fix restores older behavior of including a main asset as a variant of itself in the manifest if it exists.

This fix also includes a non-user-visible behavior change:

  • "dpr" is no longer a required field in the asset manifest's underlying structure. For the main asset entry, we do not include "dpr". It makes less sense for the tool to decide what the default target dpr for an image should be. This should be left to the framework.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@andrewkolos andrewkolos added tool Affects the "flutter" command-line tool. See also t: labels. a: assets Packaging, accessing, or using assets labels Jun 2, 2023
@andrewkolos andrewkolos force-pushed the fix-nonexistant-main-asset-case branch from 5b21625 to d9ac087 Compare June 3, 2023 01:06
@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jun 3, 2023
@andrewkolos andrewkolos force-pushed the fix-nonexistant-main-asset-case branch from 6a5ffdd to 6663e52 Compare June 4, 2023 20:45
@andrewkolos
Copy link
Contributor Author

Google testing is failing because g3 generates its own asset manifest, so that code is still out-of-date.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM with nit

@andrewkolos andrewkolos force-pushed the fix-nonexistant-main-asset-case branch from e974b73 to 56ab42c Compare June 6, 2023 18:47
@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 7, 2023
@auto-submit auto-submit bot merged commit 759ebef into flutter:master Jun 7, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 7, 2023
andrewkolos added a commit to andrewkolos/flutter that referenced this pull request Jun 7, 2023
…ts exist (flutter#128143)

Fixes flutter#127090.

flutter#122505 did a few things to speed up the first asset load that a flutter app performs. One of those things was to not include the main asset in its own list of variants in the asset manifest. The idea was that we know that the main asset always exists, so including it in its list of variants is a waste of storage space and loading time (even if the cost was tiny).

However, the assumption that the main asset always exists is wrong. From [Declaring resolution-aware image assets](https://docs.flutter.dev/ui/assets-and-images#resolution-aware), which predates flutter#122505:

> Each entry in the asset section of the pubspec.yaml should correspond to a real file, with the exception of the main asset entry. If the main asset entry doesn�t correspond to a real file, then the asset with the lowest resolution is used as the fallback for devices with device pixel ratios below that resolution. The entry should still be included in the pubspec.yaml manifest, however.

For example, it's valid to declare `assets/image.png` as an asset even if only `assets/3x/image.png` exists on disk.

This fix restores older behavior of including a main asset as a variant of itself in the manifest if it exists.

This fix also includes a non-user-visible behavior change:
* `"dpr"` is no longer a required field in the asset manifest's underlying structure. For the main asset entry, we do not include `"dpr"`. It makes less sense for the tool to decide what the default target dpr for an image should be. This should be left to the framework.
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 7, 2023
Roll Flutter from 0b74153 to 8a5c22e (46 revisions)

flutter/flutter@0b74153...8a5c22e

2023-06-07 [email protected] Super tiny MediaQuery doc update (flutter/flutter#127904)
2023-06-07 [email protected] Revert "Make inspector weakly referencing the inspected objects." (flutter/flutter#128436)
2023-06-07 [email protected] Update menu API docs to help developers migrate to m3 (flutter/flutter#128351)
2023-06-07 [email protected] [tools] allow explicitly specifying the JDK to use via a new config setting (flutter/flutter#128264)
2023-06-07 [email protected] Roll Flutter Engine from 6f9df0f988c1 to 59d5444cf06c (3 revisions) (flutter/flutter#128376)
2023-06-07 [email protected] Do not try to load main/default asset image if only higher-res variants exist (flutter/flutter#128143)
2023-06-07 [email protected] Addressed Ambiguity in transform.scale constructor docs (flutter/flutter#128182)
2023-06-07 [email protected] Super tiny fix of dead link (flutter/flutter#128160)
2023-06-07 [email protected] Refactor tests (flutter/flutter#128371)
2023-06-07 [email protected] Make inspector weakly referencing the inspected objects. (flutter/flutter#128095)
2023-06-07 [email protected] Add viewId to PointerEvents (flutter/flutter#128287)
2023-06-07 [email protected] Show error message in release mode when box is not laid out without losing performance (flutter/flutter#126302)
2023-06-06 [email protected] Roll Flutter Engine from ca499463ec2e to 6f9df0f988c1 (1 revision) (flutter/flutter#128363)
2023-06-06 [email protected] Update Draggable YouTube video link (flutter/flutter#128078)
2023-06-06 [email protected] Remove more rounding hacks from TextPainter (flutter/flutter#127826)
2023-06-06 [email protected] Roll Flutter Engine from 4571695f9e76 to ca499463ec2e (1 revision) (flutter/flutter#128356)
2023-06-06 [email protected] [Android] Update plugin and module templates to use Flutter constant for `compileSdkVersion` (flutter/flutter#128073)
2023-06-06 [email protected] handleSelectWord in MultiSelectableSelectionContainerDelegate should handle rects inside of rects (flutter/flutter#127478)
2023-06-06 [email protected] [flutter_tools] never tree shake 0x20 (space) font codepoints on web (flutter/flutter#128302)
2023-06-06 [email protected] Remove `textScaleFactor` dependent logic from `AppBar` (flutter/flutter#128112)
2023-06-06 [email protected] Roll Flutter Engine from b6d37f8f74ad to 4571695f9e76 (6 revisions) (flutter/flutter#128350)
2023-06-06 [email protected] Fix `Null check operator used on a null value` on TextField with contextMenuBuilder (flutter/flutter#128114)
2023-06-06 [email protected] Roll Packages from db4e5c2 to da72219 (10 revisions) (flutter/flutter#128348)
2023-06-06 [email protected] Updating cirrus docker image to ubuntu focal. (flutter/flutter#128291)
2023-06-06 [email protected] Adding example for migrating to navigation drawer (flutter/flutter#128295)
2023-06-06 [email protected] Roll Flutter Engine from 722aad83e5fe to b6d37f8f74ad (2 revisions) (flutter/flutter#128341)
2023-06-06 [email protected] Clean-up viewId casts in flutter_test (flutter/flutter#128256)
2023-06-06 [email protected] Update cherry-pick issue template to more uniform labels. (flutter/flutter#128333)
2023-06-06 [email protected] Use Material3 in the 2D viewport tests (flutter/flutter#128155)
2023-06-06 [email protected] Use a `show` over a `hide` for `test_api` exports (flutter/flutter#128298)
2023-06-06 [email protected] Roll Flutter Engine from aaa7574375a6 to 722aad83e5fe (1 revision) (flutter/flutter#128307)
2023-06-06 [email protected] Migration guide for moving from BottomNavigationBar to NavigationBar (flutter/flutter#128263)
2023-06-06 [email protected] [web] Use 'Uri' instead of 'dart:html' to extract pathname (flutter/flutter#127983)
2023-06-06 [email protected] Roll Flutter Engine from 2b353ae90731 to aaa7574375a6 (4 revisions) (flutter/flutter#128301)
2023-06-05 [email protected] Roll Flutter Engine from 220ece4d9faa to 2b353ae90731 (1 revision) (flutter/flutter#128293)
2023-06-05 49699333+dependabot[bot]@users.noreply.github.com Bump actions/labeler from 4.0.4 to 4.1.0 (flutter/flutter#128290)
2023-06-05 [email protected] Roll Flutter Engine from 7f12e3497428 to 220ece4d9faa (6 revisions) (flutter/flutter#128282)
2023-06-05 [email protected] [framework] attempt non-key solution (flutter/flutter#128273)
2023-06-05 [email protected] [labeler] Fix adding labels when name is directory (flutter/flutter#128243)
2023-06-05 [email protected] Remove scrollbar deprecations isAlwaysShown and hoverThickness (flutter/flutter#127351)
2023-06-05 [email protected] Fix update drag error that made NestedScrollView un-scrollable (flutter/flutter#127718)
2023-06-05 [email protected] Roll Flutter Engine from f9f72388a4da to 7f12e3497428 (4 revisions) (flutter/flutter#128271)
2023-06-05 [email protected] Migrate SemanticsBinding to onSemanticsActionEvent (flutter/flutter#128254)
2023-06-05 [email protected] Roll Flutter Engine from c838a1b05924 to f9f72388a4da (19 revisions) (flutter/flutter#128252)
2023-06-05 [email protected] [framework] force flexible space background to rebuild. (flutter/flutter#128138)
2023-06-05 [email protected] Roll Packages from 75085ed to db4e5c2 (4 revisions) (flutter/flutter#128246)
...
auto-submit bot pushed a commit that referenced this pull request Jun 9, 2023
@andrewkolos andrewkolos deleted the fix-nonexistant-main-asset-case branch June 15, 2023 01:00
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: assets Packaging, accessing, or using assets autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: 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.

Unable to load image asset on low-res devices if only high-resolution variants exist

2 participants