spark-ssr 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server.js +15 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spark-ssr",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Zero-config SSR for spark-html on Bun. The HTML template infers everything: filesystem routing, layouts, <spark-ssr> declarative data (SQL, URLs, globs, modules), auto CRUD with validation, guards, no-JS forms, schema + seeds, live updates, SEO. No build step.",
|
|
5
5
|
"homepage": "https://wilkinnovo.github.io/spark-html",
|
|
6
6
|
"type": "module",
|
package/src/server.js
CHANGED
|
@@ -303,7 +303,21 @@ export async function serve(options = {}) {
|
|
|
303
303
|
// controlled client's sockets around) piles them up until the tab hangs
|
|
304
304
|
// loading. Freeing the socket the instant we leave keeps the pool clear;
|
|
305
305
|
// reopen if the page is restored from the back/forward cache.
|
|
306
|
-
|
|
306
|
+
// A service worker must never control a spark-ssr dev page: the dev server
|
|
307
|
+
// ships none, so a controller is always a leftover from a PREVIOUS project on
|
|
308
|
+
// this same localhost port. A stale caching worker serves old HTML (so fixes
|
|
309
|
+
// never appear), holds the per-host sockets live reload needs, and throws
|
|
310
|
+
// Cache.put() errors on aborted navigations — the tab hangs and no amount of
|
|
311
|
+
// rescaffolding helps, because deleting files never unregisters a worker.
|
|
312
|
+
// Unregister it, drop its caches, reload once (a session flag stops any loop).
|
|
313
|
+
const RELOAD_CLIENT = '<script>(()=>{'
|
|
314
|
+
+ 'if(navigator.serviceWorker&&navigator.serviceWorker.controller&&!sessionStorage.getItem("__spark_sw")){'
|
|
315
|
+
+ 'sessionStorage.setItem("__spark_sw","1");'
|
|
316
|
+
+ 'console.warn("[spark-ssr] a stale service worker was controlling this dev page — unregistering it and clearing its caches");'
|
|
317
|
+
+ 'navigator.serviceWorker.getRegistrations().then(r=>Promise.all(r.map(x=>x.unregister())))'
|
|
318
|
+
+ '.then(()=>window.caches?caches.keys().then(k=>Promise.all(k.map(x=>caches.delete(x)))):0)'
|
|
319
|
+
+ '.then(()=>location.reload());return}'
|
|
320
|
+
+ 'let e,d=0;const open=()=>{e=new EventSource("/__spark/reload");'
|
|
307
321
|
+ 'e.onmessage=()=>location.reload();e.onerror=()=>{d=1};e.onopen=()=>{if(d)location.reload()}};open();'
|
|
308
322
|
+ 'addEventListener("pagehide",()=>{if(e)e.close()});'
|
|
309
323
|
+ 'addEventListener("pageshow",v=>{if(v.persisted)open()})})()</script>';
|