NYPL-Simplified/web-reader

skipWaiting for SW to be installed

Closed this issue · 3 comments

According to my reading (https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil) and tests

event.waitUntil(installSW);

Requires a thenable, not a function. Should it not be

event.waitUntil(installSW());

?

event.waitUntil(installSW); should be fine with the way installSW was written, it's an async function without an inner function.

The caching does not happen on the initial install but after the client fetches the manifests and other resources.

self.addEventListener('message', async (event) => {

Is there any error you are seeing with this function? I am happy to debug the issue together.

Thanks @Toxiapo . Did you actually test it? For me it simply never executes at all without the parentheses. My understanding of the method signature suggests that would also be the expected behaviour (or an error). The method expects a promise, not a method as a parameter. Being an async method, it returns a promise only if it is actually executed.

If you do try and test, you would need to check whether you actually get a SW waiting or not, as the log method doesn't print when the build is production. Everything works as expected with parentheses, it doesn't work at all for me without.

@AntonOfTheWoods Ahh good catch! You are right, the function did not work for me without the parentheses!!

Feel free to make a PR with the fix! : )