kit
kit copied to clipboard
feat: expose paths to service worker
closes #4714
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.
Tests
- [x] Run the tests with
pnpm testand lint the project withpnpm lintandpnpm check
Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.
For issue #4714. I couldn't find a clear example of service worker functionality being tested in the existing tests and didn't know if Playwright browser context was the right way to go about things. I did make an example project to verify this functionality is working and it can be found here. Also my IDE warned me that service workers doesn't have an exported member 'paths'. I assumed this was something that would need to be changed in the LSP project.
Lots of unknowns for me. Just starting contributing to open source...
🦋 Changeset detected
Latest commit: 860ddeea249fad7b29b63844852de353992acf6f
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @sveltejs/kit | Minor |
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
Thank you! I added the needed types. @Rich-Harris correct me if I'm wrong but I think this also fixes #2571 ? It seems things have changed quite a bit since then and the service worker stuff is since generated through Vite.
@sellenth can you run pnpm format to fix the lint error?
@dummdidumm ah that type must have been hiding in plain sight, thanks for that and the other tweaks you did.
@benmccann got it.
correct me if I'm wrong but I think this also fixes https://github.com/sveltejs/kit/issues/2571 ?
It does not — service workers !== web workers
Thank you. There is one wrinkle here that I think is worth discussing though — not sure how big a problem it is.
When you set a value for paths.assets, it is applied to the production build (including prerendered pages), but during dev and preview it is replaced with /_svelte_kit_assets so that you can reference assets that don't yet live at the specified path. It's not perfect (since prerendered pages will point to paths.assets regardless), but without it, previews are altogether impossible if you set assets.
With this change, the local preview and the service worker will have different ideas about paths.assets, which feels like it could be a source of substantial confusion. I don't have a good solution to hand, unfortunately.
Revisiting this PR: my previous objection is rescinded because it makes no sense. You can't build a service worker when paths.assets is set, because the two things are fundamentally incompatible.
Given that, it doesn't really make sense to expose paths, since paths.assets will always be identical to paths.base. Instead, we should just expose base. While we're at it, we can compute base at runtime (instead of hardcoding it — this means the resulting assets more portable), and use it for the build, files and prerendered arrays.
I implemented all that in #9250, so I'll close this PR. Thanks!