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

Custom Rules should come after generated rules #132

Closed
tacman opened this issue Mar 13, 2024 · 3 comments · Fixed by #135
Closed

Custom Rules should come after generated rules #132

tacman opened this issue Mar 13, 2024 · 3 comments · Fixed by #135
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@tacman
Copy link
Contributor

tacman commented Mar 13, 2024

Version(s) affected

1.1.x

Description

Until I can figure out how to map rules to the pwa.yaml, I'm just adding them as custom rules. These come from the PWA-IndexedDB tutorial, their sw.js is at https://github.com/paritoshtripathi/PWA-Sample-IndexedDB/blob/master/solution/app/sw.js
and I'm trying to re-create the application without custom javascript.

  workbox.precaching.precacheAndRoute([]);

  const showNotification = () => {
    self.registration.showNotification('Background sync success!', {
      body: '🎉`🎉`🎉`'
    });
  };

  const bgSyncPlugin = new workbox.backgroundSync.Plugin(
    'dashboardr-queue',
    {
      callbacks: {
        queueDidReplay: showNotification
        // other types of callbacks could go here
      }
    }
  );

  const networkWithBackgroundSync = new workbox.strategies.NetworkOnly({
    plugins: [bgSyncPlugin],
  });

  workbox.routing.registerRoute(
    /\/api\/add/,
    networkWithBackgroundSync,
    'POST'
  );

How to reproduce

Add the above the sw.js.

The problem is that my rules come at the top of the js file, before all the assetmapper files have been loaded.

Possible Solution

Generate from yaml first, then custom rules?

Or re-add the placeholders like version 1.0 had

Additional Context

No response

@Spomky
Copy link
Member

Spomky commented Mar 16, 2024

Seems legit to me.
This will be fixed.
Note that do not want to go back to placeholders. It is possible to use priority to allow rules to be on top or at the end of the file (for services only).

@Spomky Spomky self-assigned this Mar 16, 2024
@Spomky Spomky added the enhancement New feature or request label Mar 16, 2024
@Spomky Spomky added this to the 1.1.0 milestone Mar 16, 2024
@tacman
Copy link
Contributor Author

tacman commented Mar 16, 2024

It is possible to use priority to allow rules to be on top or at the end of the file (for services only).

Can you provide an example of user-defined (application-level) services? Maybe that's where I can hook in my pre-cached routes.

@Spomky Spomky linked a pull request Mar 17, 2024 that will close this issue
4 tasks
@Spomky Spomky mentioned this issue Mar 17, 2024
4 tasks
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants