-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[web] Make asset manifest immediately available to app (no network request) #130419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
packages/flutter_tools/lib/src/web/file_generators/main_dart.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/services/_asset_manifest_contents_io.dart
Outdated
Show resolved
Hide resolved
|
@jonahwilliams I found a problem with this approach. It works for However, this doesn't work for There might be a way to rework these targets to make these work, but if it turns out to be difficult, I may end up just generating another JSON asset manifest, as much I would not like to. |
|
Just change the dependency chain? |
Yeah that's what I am going to try. In hindsight, I didn't mean to sound so pessimistic lol |
33aa21d to
db5bbc3
Compare
|
I tried changing the dependency chain for web builds to build the asset bundle before compiling any code (so we can inject the asset manifest into code before compiling) (see db5bbc3). However, this didn't work because icon tree shaking (which is part of errorfyi: To make the idea of injecting the asset manifest into the dart code we compile work, we would have to do one of the following:
None of these solutions seem great. Alternatively, another thing we can do to support the Yet another (already mentioned) alternative is to generate another version of the asset manifest that isn't a At this point I am considering closing this PR since my work on this has far over-exceeded the amount of time I allotted myself to work on this, but I will discuss with @jonahwilliams before then. |
|
Another option I've just now realized is that I could just try the service worker thing (I still need to test this with IDM). Developers with IDM will still run into the issue when they |
|
Ahh yeah, the asset bundle depending on the results of compilation for tree shaking is unfortunate. I think building the bundle twice is probably the most reasonable way to do it. By default I don't think copy assets (the helper function) will write any data, so you could do that in the same target that generates the entrypoint |
13b655b to
163d23f
Compare
|
Marking this as ready for review. I wanted to get Google testing unstuck first, but I had no success. edit: oops, forgot to replace the WIP text in the description. Will do that and then request review from the web team. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems out of date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in commit fix documented [sic.] of loadAssetManifest in _load_asset_manifest_io.dart
packages/flutter/lib/src/painting/_load_asset_manifest_web.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean all four of these lines? Don't we need to call build to generate the asset manifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deferredComponentsEnabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I think we can remove this since deferred components assets are written to the asset manifest the same way any other asset is. Addressed with commit simplify call to assetBundle.build
This reverts commit e45151778e87bdf0cef178d62eb8057c3998f4d9.
* Move load_asset_manifest to services * Restore image_resolution.dart * Conditionally loadAssetManifest from bundle. * Simplify js-interop, and avoid having two copies of the manifest in memory. * Prevent web version from calling AssetManifest.loadFromAssetBundle(bundle); (It's a recursive call now)
404a406 to
d7d61e3
Compare
|
@andrewkolos has this PR been superceded by #131382 ? |
Fixes #124883. See #128456 for more history.
Context
The asset manifest is a file generated by the tool at build time that lists available assets and their variants. The framework loads this file when resolving assets (e.g. from an
Image.assetcall) (It's also meant to be pre-loaded when the app first loads, but this is currently broken, see #130455).However, should this load operation fail, assets will fail to load unless the end-user of the app re-opens it. This is far more likely to happen in Flutter web, since file loads must happen over a potentially unreliable network where requests can fail or be intercepted.
Fix
At build time, we take the contents of the asset manifest and include it as a constant in the code we generate for web app's entry point. This way, the asset manifest is available without making a network request specifically for it.
We do this for both the
flutter run -d <browser>andflutter build webworkflows. Arguably, it would be sufficient to do this only forflutter build web(to keep things simpler); but issues like #124883 would still be confusing for developers, and they would be rightfully concerned that the issue would still affect end users.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.