-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[feat] allow to disable service worker auto inject #2988
[feat] allow to disable service worker auto inject #2988
Conversation
🦋 Changeset detectedLatest commit: c456bef 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 |
I added documentation and test. The CI fails on windows due to a timing issue (not related with this PR). I think this is ready for review. |
This generally seems reasonable to me and similar to #2281. My main question for the other maintainers would be about what we should call the option name |
@benmccann, thank you for your reply. 1/ Regarding #2281, you're right, I found this PR after implementing the feature. However, this PR takes a simpler approach: if you want to customize the service worker behavior, just disable automatic injection and do what you want 😁. It means less impact on the kit code (only 3 lines impacted) and less maintenance. 2/ Regarding the option name, I think there are two possibilities:
Let met know your preference, I will adapt the PR to your choice. |
Hello, I would like to know if it's possible to review this PR? I'm using a custom script to workaround this issue but I'm creating new projects every week and it will become very hard to maintain in the future. Thank you in advance |
Thank you! I renamed the option to |
Thank you for your intervention! |
This PR allows to disable the automatic injection of the service worker.
This allows developpers to code a custom logic to register service workers.
It is particularly useful when using
workbox
to manage the service worker.Workaround
As a workaround, I actually use a script that I run after
svelte-kit build
to strip the injected service worker fromindex.html
but it only work for SPA builds. In SSR environments, a customhook
may be able to strip it.But it's not a viable solution since it can break anytime the injected code is changed on the svelte-kit side.
Usage
In your
svelte.config.js
, you just have to set the following option:Fixes
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0Todo