Open sinbino opened 8 months ago
I recently ran into this myself and used a SvelteKit GET
endpoint to load and register the service worker manually
Would be great to not need this workaround
I couldn't get the minimal reproduction working with the provided docker compose setup. Could you provide additional instructions for starting it?
I couldn't get the minimal reproduction working with the provided docker compose setup. Could you provide additional instructions for starting it?
https://codesandbox.io/p/devbox/sveltekit-basepath-service-worker-6gydt7
very easy reproduction, just use starter template, add service worker, add base path and its broken in dev 👍🏻
https://github.com/user-attachments/assets/2e31de02-f8d4-4fc3-94ff-24a8092919c1
Describe the bug
As the title says, service-worker will not load correctly if you specify a subdirectory in config.paths.base.
The sample confirms that it works correctly if config.paths.base is not set.
For example, if config.paths.base is set to /subdir, the service-worker will fail to start. Looking at the devtools in the browser, it appears that loading https://example.com/@fs/srv/app/src/service-worker.ts is causing a 404 error.
If I open https://example.com/subdir/@fs/srv/app/src/service-worker.ts directly in my browser, the source can be read, so I think config.paths.base is not reflected in this section.
Reproduction
The sample repository is as follows https://github.com/sinbino/issue-sveltekit-paths-base-serviceworker I just added a small service-worker to the skeleton code created by npm create sveltekit. However, since service-worker requires https to work, you may have to go through a reverse proxy that supports SSL to see it work.
When executed, the following error is printed to the console, confirming that the service worker is not running.
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response