Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flutter.js] Wait for reg.update, then activate sw (if not active yet). #101464

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

Merged
merged 6 commits into from
Apr 12, 2022
Merged

[flutter.js] Wait for reg.update, then activate sw (if not active yet). #101464

merged 6 commits into from
Apr 12, 2022

Conversation

ditman
Copy link
Member

@ditman ditman commented Apr 6, 2022

In this PR we handle the update case of Flutter Web service worker slightly better, by awaiting on the promise returned by it, instead of using the instance upon which update was called.

Once that's done, we fetch the service worker in the state in which it might be, and pass it to the method that waits for its activation (if needed!).

Fixes #101459

Tests: Added a test that goes through the code path that was failing, but I couldn't reproduce the failure :/

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 6, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@ditman ditman requested a review from yjbanov April 6, 2022 23:42
Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

Is there a way to test this?

@yjbanov
Copy link
Contributor

yjbanov commented Apr 6, 2022

Oh, wait, I missed your comment:

Tests: couldn't test this, because AFAIK we don't have the ability to swap a Flutter Web service worker on the fly in our testing environment :/

What causes the service worker to change to trigger this code path? This test is attempting to do something like that:

https://github.com/flutter/flutter/blob/master/dev/bots/service_worker_test.dart

@ditman
Copy link
Member Author

ditman commented Apr 7, 2022

What causes the service worker to change to trigger this code path? This test is attempting to do something like that:

I think what we need to do is to have:

  • An app running with a given serviceWorkerVersion, so it registers that serviceWorker (v1)
  • Rebuild the app with a different serviceWorkerVersion (v2)
  • Refresh the app. That should trigger the "serviceWorkerVersion is different, I need to update the SW" branch of the code

(I think, not entirely sure)

@ditman
Copy link
Member Author

ditman commented Apr 7, 2022

I've added a new test to service_worker_test.dart that implements what I described above:

  1. Load app v1
  2. Reload app v1
  3. Change app to v2
  4. Load app v2

That does exercise the code path where the serviceworker IS updated, but it doesn't trigger the issue on my machine :S

Also expanded the service worker test to have 3 different initializations: without flutter js, with flutter js and all the steps, and with flutterJS "short" (calling autoStart directly).

@ditman ditman requested a review from yjbanov April 7, 2022 03:50
@flutter-dashboard flutter-dashboard bot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Apr 7, 2022
…is maintained after the service_worker_test.dart ends.
Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

lgtm

@fluttergithubbot fluttergithubbot merged commit bee95b6 into flutter:master Apr 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 12, 2022
@ditman ditman deleted the fix-service-worker-update-corner-case branch April 12, 2022 17:27
muditatandon pushed a commit to muditatandon/flutter that referenced this pull request May 5, 2022
muditatandon added a commit that referenced this pull request May 5, 2022
…103101)

* Add the new hash

* [flutter.js] Wait for reg.update, then activate sw (if not active yet). (#101464)

* Avoid scheduling a forced frame when there is no child to the renderView (#102556)

* Migrate AppBar to Material 3 (#101884)

* Keeping the super parameters

* Fixing semi-colon issue

Co-authored-by: David Iglesias <[email protected]>
Co-authored-by: Dan Field <[email protected]>
Co-authored-by: Darren Austin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[web] ServiceWorker "installing" may be null right after calling "update()"
3 participants