Skip to content
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: expose paths to service worker #8472

Closed
wants to merge 7 commits into from
Closed

Conversation

sellenth
Copy link

@sellenth sellenth commented Jan 12, 2023

closes #4714

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

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-bot
Copy link

changeset-bot bot commented Jan 12, 2023

🦋 Changeset detected

Latest commit: 860ddee

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

@dummdidumm dummdidumm changed the title added paths to service worker (issue #4714) feat: expose paths to service worker Jan 12, 2023
@dummdidumm
Copy link
Member

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.

@benmccann
Copy link
Member

@sellenth can you run pnpm format to fix the lint error?

@sellenth
Copy link
Author

@dummdidumm ah that type must have been hiding in plain sight, thanks for that and the other tweaks you did.

@benmccann got it.

@Rich-Harris
Copy link
Member

correct me if I'm wrong but I think this also fixes #2571 ?

It does not — service workers !== web workers

@Rich-Harris
Copy link
Member

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.

@Rich-Harris
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose paths to $service-worker module
4 participants