[web] Add onEntrypointLoaded to FlutterLoader.#108776
Merged
auto-submit[bot] merged 4 commits intoflutter:masterfrom Aug 3, 2022
ditman:web-hot-restart-proper-init
Merged
[web] Add onEntrypointLoaded to FlutterLoader.#108776auto-submit[bot] merged 4 commits intoflutter:masterfrom ditman:web-hot-restart-proper-init
auto-submit[bot] merged 4 commits intoflutter:masterfrom
ditman:web-hot-restart-proper-init
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current promise-based API of flutter.js to inject the entrypoint and report back with an "engine initializer" object does not work well with Flutter web's hot-restart feature, and in fact, reverts to "auto" initialization upon hot restart as a "fix". See: #108403. This is a problem for incoming changes on flutter, where we might want to pass custom parameters to the
initializeEngine/runAppJS methods.onEntrypointLoadedeventThis PR adds a new
onEntrypointLoadedmethod to the FlutterLoader provided by flutter.js that triggers a new "flutter:entrypoint-loaded" event every time the app (hot)restarts, so the rest of the custom initialization code can run.The new init sequence of a flutter app that survives hot-restart looks like:
This separation also makes quite obvious what things will run once (
loadEntrypoint) vs what will run every time the engine hot-restarts (onEntrypointLoaded).Detangle flutter.js ServiceWorkerLoader from EntrypointLoader
In a first (small) step towards modularization of the library, this change detangles the old "loadWithServiceWorker" logic into: load service worker, then load the entrypoint.
The old logic basically attempted very hard to load a service worker, but if for any case it'd fail, it'd always "fall back" to the _loadEntrypoint method.
The new logic separates the Service Worker install logic from the Entrypoint loader, so it can be loaded in two steps:
The new structure makes it easier to ES-Modularize the file in the future, or inject custom behavior for any/all of the steps of the bootstrap. (Some extra modularization is still required from the FlutterLoader bits, but this looks like a nice start).
Issues
Tests
Backwards-compatibility
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.