-
Notifications
You must be signed in to change notification settings - Fork 822
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
Unexpected behaviour when manually constructing PrecacheController #2665
Comments
(CC: @philipwalton as he's done more recent investigation around Do you want your service worker to be installed at all when there's a redirection performed? If the redirection means that your service worker installation should fail, one approach would be to use the default Something like:
|
I do not want the service worker to successfully install if a redirect occurs, as this means the user should be taken to the login page, which should not handled be the service worker (it's served from server side static html separate from the app due to project specifics). I'll give your suggestion a go! What is the significance of adding a listener to the install event before the edit: I've added that last bit, as typically when using an API the user shouldn't have to worry about the complexities of any specific events the underlying API may be registering. Due to Javascripts async nature a user should be able to register a listener anywhere in a synchronous file, only having to worry about the order of their own listeners. Hence the |
A service worker's listeners listeners for a given event are executed sequentially, and synchronously, in the order in which they're registered. If your There are some restrictions in the service worker specification that mean you need to register all event listeners as part of the initial, top-level, execution of the service worker script—officially, you can't register additional listeners after that. |
Thank you for clearing up the whole listener thing! I've been using service-workers passively for a while. But it's only been in the past 2 days i've really deep dived into all their capabilities, particularly surrounding workbox. |
Although I could make a fetch against an auth endpoint before installation, I've gone back to the plugin approach to test. On initial load, all requests return a 200, meaning the plugin model should allow the request to be cached and the installation successful.
|
I don't know if this is the same issue but the Uncaught (in promise) non-precached-url: non-precached-url :: [{"url":"/rudder//index.html"}] Given a {
"name": "Rudder",
"short_name": "Rudder",
"icons": [
{
"src": "/rudder/rudder-icon.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "/rudder/index.html",
"theme_color": "#4a148c",
"background_color": "#000000",
"display": "standalone"
} It looks that somehow The built updateI suspect this is a Create React App issue - still investigating |
@johnnyreilly, is this |
C-R-A 3 Just had a look at 4 and it has a different approach. (Implemented by you I think 🤗) facebook/create-react-app#9205 I'm pondering upgrading to C-R-A 4 and seeing if it resolves this. Good shout? |
Yeah, I'd switch to |
I'll give it a go - thanks! |
Hi there, Workbox is moving to a new engineering team within Google. As part of this move, we're declaring a partial bug bankruptcy to allow the new team to start fresh. We realize this isn't optimal, but realistically, this is the only way we see it working. For transparency, here're the criteria we applied:
Thanks, and we hope for your understanding! |
Library Affected:
workbox-precaching
Browser & Platform:
Google Chrome latest
Issue or Feature Request Description:
Using Workbox v5.1.4.
I have a use case where I want to fully utilise the precaching of my app shell, besides in the scenario where our server deems under certain circumstances that the user should be redirected. This redirection will occur on the base route / . This redirection will then be handled by the
precacheController
using the registered index.html asset given toprecacheAndRoute
, serving the user the cache index.html app shell rather than the browser redirecting to the page being served by a different server (same origin).I have tried constructing my own precacheController and invoking install manually on it, inside the install listener. Passing install a plugins array containing a
cacheWillUpdate
plugin. Ideally preventing installation of the service worker if the redirect on / is present. Causing the user to be redirected correctly.// issue lies here
This approach appears not to be very consistent, depending on the order i construct things, i either never get a successful installation of the service worker on first load (on 200 where the index.html should be cached). Or an error is thrown when trying to grab index.html "c.handle is not a function" (minified workbox). I've added a default handler for it to fallback on, however it seems to be trying to call
handle
on the PrecacheController instance rather than its handler...// Attempts to work around
Furthermore, I have also tried registering a
NetworkFirst
strategy for just the index.html before theprecacheAndRoute
is called with the assets. This works great, however, i then lose the Navigation routing fromcreateHandlerBoundToURL
on longer urls and ones with queries, which is very important for our use-cases!It seems like in Workbox v6 the PrecacheController has changed slightly to accept plugins as a parameter in its constructor. However i would not like to update as i'm using create-react-app for my webpack config.
The text was updated successfully, but these errors were encountered: