perf/audit-phase-0-1
The update prompt reappeared after every refresh, forever.
Root cause: the worker was registered with `{ type: 'module' }`, but
SvelteKit/Vite bundles src/service-worker.js down to a classic script with no
imports or exports (verified: zero import/export statements in the build
output). Registering a classic script as a module made the browser install a
fresh worker on every register() call — so every page load produced a
"waiting" worker, which is precisely the signal the prompt keys off. Clicking
Refresh activated that worker and the next load did the same thing again.
Reproduced deterministically before the fix: with byte-identical script bytes
(confirmed by hashing two fetches), a single registration and a single scope,
every load still ended with waiting: "installed" and the prompt visible.
After removing the option, three consecutive loads of the same build leave no
waiting worker and no prompt.
Two related defects found while investigating:
- controllerchange fired a full page reload on a FIRST visit. The worker calls
clients.claim(), so a page that starts with no controller gets one, which is
a controllerchange — every new visitor was silently getting a redundant
reload. Now guarded on whether the page had a controller to begin with.
- A worker already waiting from a previous visit was invisible. `updatefound`
does not fire for one that is already installed, so someone who closed the
tab with an update pending would never be offered it again. The waiting
worker is now checked at registration time.
Also clears the prompt when Refresh is clicked rather than leaving it up
during the hand-over.
Verified the full lifecycle against two real builds: unchanged build across
repeated loads shows no prompt; a genuinely new build shows it; clicking
Refresh activates the worker and the prompt does not return on reload; the
previous version's cache is pruned.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
sv
Everything you need to build a Svelte project, powered by sv.
Creating a project
If you're seeing this, you've probably already done this step. Congrats!
# create a new project in the current directory
npx sv create
# create a new project in my-app
npx sv create my-app
Developing
Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
Building
To create a production version of your app:
npm run build
You can preview the production build with npm run preview.
To deploy your app, you may need to install an adapter for your target environment.
Languages
TypeScript
56.7%
Svelte
36.1%
JavaScript
3.4%
Shell
2.7%
CSS
0.8%
Other
0.3%