Repository navigation
[flutter_tools] register service worker after first frame event - #66082
Conversation
|
I think my changes to the binding should be reasonable... :) |
| <script> | ||
| if ('serviceWorker' in navigator) { | ||
| window.addEventListener('load', function () { | ||
| window.addEventListener('flutter-first-frame', function () { |
There was a problem hiding this comment.
this event is dispatched by the flutter binding
There was a problem hiding this comment.
There's probably some people with the old addEventListener('load'...), how do we normally communicate this type of changes to users? A tweet/blog post/something else?
There was a problem hiding this comment.
hmmm, its not really a breaking change. Probably the changelog?
| } | ||
|
|
||
| List<void Function(Duration)> postFrameCallbacks; | ||
| List<void Function(Duration)> postFrameCallbacks = <void Function(Duration)>[]; |
There was a problem hiding this comment.
this needs to be initialized to a non-null value.
ditman
left a comment
There was a problem hiding this comment.
This looks good to me, I left a few comments but I don't think they're blocking at all.
(I don't push much to flutter/flutter, so you're probably more familiar than I am with the severity of the broken CI checks, though!)
|
Friendly ping @ditman :) |
| assert(renderView != null); | ||
| addPersistentFrameCallback(_handlePersistentFrameCallback); | ||
| initMouseTracker(); | ||
| if (kIsWeb) { |
There was a problem hiding this comment.
How does this behave with hot restart? Does it get called again?
There was a problem hiding this comment.
it does get called again, but now (thanks to @yjbanov ) in run mode we definitely do not create a real service worker so it would only reload an empty script.
| void _handleWebFirstFrame(Duration _) { | ||
| assert(kIsWeb); | ||
| const MethodChannel methodChannel = MethodChannel('flutter/service_worker'); | ||
| methodChannel.invokeMethod<void>('first-frame'); |
There was a problem hiding this comment.
btw, you are not checking for the method name in the engine.
There was a problem hiding this comment.
I don't think it is important unless we expand the number of actions here. i.e. building in service worker auto-update dialog or something.
Description
Registering the service worker immediately after the documented has loaded may cause SW initialization to compete with framework initialization. It was recommended to us that we defer the service worker setup until after the framework is done with setup, which should be sometime after the first frame.
To implement this, I augmented the binding setup to dispatch an event on the document after the binding has initialized. I don't see any obvious risks with this setup.
Fixes #66066