-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Fix: Adding path normalization for service worker #1437
Conversation
🦋 Changeset detectedLatest commit: 6f7d229 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b548c2c
to
ba2a41d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reasoning behind this change?
This wont work for most cases where __webpack_public_path__
is different from /
.
- A service worker from a different domain is not allowed to control your web app.
- A service worker from a subpath would only control that subpath which is not the use case of preact-cli's SW
Give me a bit of rope here while I explain, certainly not an expert. I was deploying a small site to GH pages. The problem that then sprung up was the lack of a trailing Certainly let me know if this just shouldn't be done this way or what. Certainly possible I found the worst solution to the issue. I assume this falls under the "controlling a subpath is not the use case of preact-cli's SW", so perhaps this is just something that I should disable instead. |
@rschristian so sorry didn't mean to sound rude in my previous comment. apologies. i feel we need to have a customizable way of registering service worker, so that we build it just the way we do today and let users register it for a subpath. |
@prateekbh No worries, I didn't think it was remotely rude. I was just trying to convey that this may very well be a hacky solution on top of a hacky solution. My knowledge in this area is super lacking. Is letting users register a SW for a subpath something for this PR to fix, maybe something this PR can be merged into, or just something else entirely? While I do believe that I understand that SWs + use of Edit: At least as far as I'm aware. Does this have some bigger impact I'm not seeing? |
Whoops, accidentally recreated this in #1648 |
What kind of change does this PR introduce?
Bug fix
Did you add tests for your changes?
No, I did not. If this warrants a test I can of course write one up.
Summary
I needed to change the
publicPath
of an application (viaconfig.output.publicPath = ...
in mypreact.config.js
) when I noticed the SW import was not normalized. If my path washttps://example.com/project
, the service worker would error out in the console with the URL ofhttps://example.com/projectsw.js
. Simple normalization issue.The function to normalize URLs was already written so all I did was wrap the usage of
__webpack_public_path__
with that function.Does this PR introduce a breaking change?
No breaking changes