Skip to content

InjectionToken SwRegistrationOptions is ignored when using standalone bootstrapApplication function. #57824

Closed as not planned

Description

@antur84

Which @angular/* package(s) are the source of the bug?

service-worker

Is this a regression?

Yes

Description

Hi, I've made a little repo to illustrate the issue.

When using the old NgModule based syntax to init your app with a service worker, then your provided SwRegistrationOptions is found and respected.

Runing the app gives you a console log.

When using standalone app syntax, via bootstrapApplication then your provided SwRegistrationOptions is not not found nor respected. Runing the app does not give you a console log.

Likely it was overlooked in the PR where the provideServiceWorker function was added. Or perhaps I'm just misunderstanding how it's supposed to work now.

Please provide a link to a minimal reproduction of the bug

https://github.com/antur84/sw-registration-options-bug/commits/main/

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 18.2.4
Node: 20.16.0
Package Manager: npm 10.8.1
OS: win32 x64

Angular: 18.2.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
... service-worker

Anything else?

No response

Activity

  1. modified the milestone: needsTriage on Sep 16, 2024
  2. antur84 commented on Sep 16, 2024

    @antur84
    Author

    Aha, I looked at the unit tests for the feature and noticed that there's coverage for the SwRegistrationOptions override case, and the tests are obviously green :)

    It turns out that the order is important here. One must register the custom options AFTER calling provideServiceWorker, as that function will overwrite your provider with the (non existing) options passed in as second argument.

    The following works ✅

    bootstrapApplication(AppComponent, {
      providers: [
        provideServiceWorker('ngsw-worker.js'),
        {
          provide: SwRegistrationOptions,
          useFactory: serviceWorkerInitFactory,
        },
      ],
    });
    

    While this does not work

    bootstrapApplication(AppComponent, {
      providers: [
        {
          provide: SwRegistrationOptions,
          useFactory: serviceWorkerInitFactory,
        },
        provideServiceWorker('ngsw-worker.js'),
      ],
    });
    
  3. JeanMeche commented on Aug 29, 2025

    @JeanMeche
    Member

    With #63364 we've announced that the service-worker package in now in maintenance mode and will not receive feature PRs and feature requests.

    The message is also visible here: https://angular.dev/ecosystem/service-workers

  4. angular-automatic-lock-bot commented on Sep 29, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions