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

Workbox-build, empty callbacks for backgroundSync runtimeCaching options #1761

Closed
dandro32 opened this issue Nov 16, 2018 · 2 comments
Closed
Labels
Bug An issue with our existing, production codebase. Good First Issue This would be an ideal issue for a new contributor to take on. workbox-build

Comments

@dandro32
Copy link

Hi,
I'm currently working on project based on Create React App v2.1.0 , that includes build-in workbox.
I'm generating a service worker using workbox-build. In runtimeCaching I have several caching options, including backgroundSync option, where I want to include some custom action after queueDidReplay
2018-11-16 11_48_55-sw

However, on my generated service worker there is no callback options.
sw2

Is this option is available? Or this is CRA issue?
Would be gratefull for any directions or hints.
Thanks.

@jeffposnick
Copy link
Contributor

We do make an attempt to transfer free-form function definitions inside of the runtimeCaching config into the final generated service worker code by using the stringify-object module under the hood, but only for entries in the options.plugins section:

function getOptionsString(options = {}) {
let plugins = [];
if (options.plugins) {
// Using libs because JSON.stringify won't handle functions.
plugins = options.plugins.map(stringifyWithoutComments);
delete options.plugins;
}

When using the shorthands for configuring the various plugins, like options.backgroundSync, we just use JSON.stringify(), which is what's causing what you're seeing:

case 'backgroundSync': {
const name = pluginConfig.name;
pluginCode = `new ${pluginString}(${JSON.stringify(name)}`;
if ('options' in pluginConfig) {
pluginCode += `, ${JSON.stringify(pluginConfig.options)}`;
}
pluginCode += `)`;
break;
}

I think switching the JSON.stringify() there to use the same stringify-object wrapper we're using earlier would take care of the issue.

@jeffposnick jeffposnick added Bug An issue with our existing, production codebase. Good First Issue This would be an ideal issue for a new contributor to take on. labels Nov 19, 2018
@jeffposnick
Copy link
Contributor

This is fixed in Workbox v4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An issue with our existing, production codebase. Good First Issue This would be an ideal issue for a new contributor to take on. workbox-build
Projects
None yet
Development

No branches or pull requests

2 participants