Skip to content
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

service-worker-communications: lazy-loading and promptUser #37527

Open
davewelsh opened this issue Jun 10, 2020 · 4 comments
Open

service-worker-communications: lazy-loading and promptUser #37527

davewelsh opened this issue Jun 10, 2020 · 4 comments

Comments

@davewelsh
Copy link

@davewelsh davewelsh commented Jun 10, 2020

📚 Docs or angular.io bug report

Description

@Injectable()
export class PromptUpdateService {

  constructor(updates: SwUpdate) {
    updates.available.subscribe(event => {
      if (promptUser(event)) {
        updates.activateUpdate().then(() => document.location.reload());
      }
    });
  }
}

Doing this could break lazy-loading in currently running apps, especially if the lazy-loaded chunks use filenames with hashes, which change every version.

  1. The documentation seems incomplete. What should we do if we are using lazy-loading but we want our users to update to the latest version of the app?

  2. I think it would be helpful to explain what promptUser is too. If it's function the developer is expected to write himself--which seems to be the case--then that could be made more clear like this:

@Injectable()
export class PromptUpdateService {

  constructor(updates: SwUpdate) {
    updates.available.subscribe(event => {
      if (this.promptUser(event)) {
        updates.activateUpdate().then(() => document.location.reload());
      }
    });
  }

  private promptUser(event: UpdateAvailableEvent): boolean {
    // prompt the user if now would be a good time to reload the app
  }
}

🔬 Minimal Reproduction

What's the affected URL?**

https://angular.io/guide/service-worker-communications

@atscott atscott added the comp: docs label Jun 10, 2020
@ngbot ngbot bot added this to the needsTriage milestone Jun 10, 2020
@gkalpak
Copy link
Member

@gkalpak gkalpak commented Jun 11, 2020

Thx for reporting this, @davewelsh!

  1. The Doing this could break lazy-loading in currently running apps part seems wrong. Activating the update without reloading could have that effect. But reloading the page once the update has been activated is fine. Maybe that is what we intended to say there.
    @kapunahelewong (since you seem to have authored that part), do you remember why you put it in there? Is there something else I am missing?

  2. 👍 on being more clear that promptUser() is to be implemented by the app developer.

gkalpak added a commit to gkalpak/angular that referenced this issue Jun 12, 2020
…n guide

This commit includes various fixes/improvements for the
"Service worker communication" guide.

This partially addresses angular#37527.
@gkalpak
Copy link
Member

@gkalpak gkalpak commented Jun 12, 2020

FYI, I submitted #37555 which partially addresses this issue.

gkalpak added a commit to gkalpak/angular that referenced this issue Jun 12, 2020
…n guide

This commit includes various fixes/improvements for the
"Service worker communication" guide.

This partially addresses angular#37527.
@kapunahelewong
Copy link
Contributor

@kapunahelewong kapunahelewong commented Jun 12, 2020

  1. The Doing this could break lazy-loading in currently running apps part seems wrong. Activating the update without reloading could have that effect. But reloading the page once the update has been activated is fine. Maybe that is what we intended to say there.
    @kapunahelewong (since you seem to have authored that part), do you remember why you put it in there? Is there something else I am missing?

That was actually written by the then new docs members Jen and Sreevani who were still learning the process and Angular. Jen's PR #20021 with the original content had to be reverted in #20716. So I took their work and submitted a new PR to help them through the process, but they handled comments and content. Does that context help? Regarding service worker though, I know very little.

@gkalpak
Copy link
Member

@gkalpak gkalpak commented Jun 13, 2020

Thx for the info, @kapunahelewong. This looks like an oversight, so look let's move forward with #37555.

Interestingly, there was a comment about clarifying that bit in the original PR, but it was apparently never addressed: #20021 (comment)

gkalpak added a commit to gkalpak/angular that referenced this issue Jun 13, 2020
…n guide

This commit includes various fixes/improvements for the
"Service worker communication" guide.

This partially addresses angular#37527.
mhevery added a commit that referenced this issue Jun 15, 2020
…n guide (#37555)

This commit includes various fixes/improvements for the
"Service worker communication" guide.

This partially addresses #37527.

PR Close #37555
mhevery added a commit that referenced this issue Jun 15, 2020
…n guide (#37555)

This commit includes various fixes/improvements for the
"Service worker communication" guide.

This partially addresses #37527.

PR Close #37555
ngwattcos added a commit to ngwattcos/angular that referenced this issue Jun 25, 2020
…n guide (angular#37555)

This commit includes various fixes/improvements for the
"Service worker communication" guide.

This partially addresses angular#37527.

PR Close angular#37555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.