question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

service-worker-communications: lazy-loading and promptUser

See original GitHub issue

πŸ“š 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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gkalpakcommented, 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: https://github.com/angular/angular/pull/20021#discussion_r149189505

0reactions
bob-watsoncommented, Jun 28, 2022

P3 to at least reassess where this is after 2 years of nothing happening with it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service worker communication - Angular
The SwUpdate service gives you access to events that indicate when the service worker discovers and installs an available update for your application....
Read more >
Lazy loading - Web performance | MDN
Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten theΒ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found