bun-plugin-stx 0.2.324 → 0.2.325
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/dist/serve.js +9 -5
- package/package.json +1 -1
package/dist/serve.js
CHANGED
|
@@ -9328,8 +9328,11 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9328
9328
|
const cssCssCache = boundedCache(options.cssCacheLimit ?? 512);
|
|
9329
9329
|
const hmrClients = new Set;
|
|
9330
9330
|
const hmrEncoder = new TextEncoder;
|
|
9331
|
+
let hmrVersion = 0;
|
|
9331
9332
|
function broadcastHmr(event) {
|
|
9332
|
-
|
|
9333
|
+
if (event.type !== "build-error")
|
|
9334
|
+
hmrVersion++;
|
|
9335
|
+
const payload = hmrEncoder.encode(`data: ${JSON.stringify({ ...event, version: hmrVersion })}
|
|
9333
9336
|
|
|
9334
9337
|
`);
|
|
9335
9338
|
for (const c of hmrClients) {
|
|
@@ -9375,16 +9378,17 @@ function __stxOverlay(errs){
|
|
|
9375
9378
|
el.innerHTML=h;
|
|
9376
9379
|
}
|
|
9377
9380
|
`;
|
|
9378
|
-
const HMR_CLIENT_SCRIPT = `<script data-stx-hmr>(()=>{if(window.__stxHmr)return;window.__stxHmr=1;${HMR_OVERLAY_JS}function bust(){var ls=document.querySelectorAll('link[rel="stylesheet"]');for(var i=0;i<ls.length;i++){var l=ls[i];var u=new URL(l.href,location.href);u.searchParams.set('v',Date.now().toString(36));l.href=u.toString()}}var es=
|
|
9381
|
+
const HMR_CLIENT_SCRIPT = `<script data-stx-hmr>(()=>{if(window.__stxHmr)return;window.__stxHmr=1;${HMR_OVERLAY_JS}function bust(){var ls=document.querySelectorAll('link[rel="stylesheet"]');for(var i=0;i<ls.length;i++){var l=ls[i];var u=new URL(l.href,location.href);u.searchParams.set('v',Date.now().toString(36));l.href=u.toString()}}var version=__STX_HMR_VERSION__,es=null;function swapFragment(){var r=window.stxRouter;if(r&&typeof r.refresh==='function'){try{return r.refresh().then(function(ok){if(!ok)location.reload()},function(){location.reload()})}catch(_){location.reload()}}else{location.reload()}}function reloadStores(){var s=window.stx;if(!s||typeof s.__hmrReplaceStores!=='function'){location.reload();return}fetch('/_stx/stores.js',{cache:'no-store'}).then(function(r){return r.ok?r.text():null}).then(function(code){if(code===null){location.reload();return}s.__hmrReplaceStores(code)}).catch(function(){location.reload()})}function connect(){var source=new EventSource('/_stx/hmr');es=source;source.onmessage=function(e){try{var m=JSON.parse(e.data);if(m.type==='connected'){if(typeof m.version==='number'&&m.version!==version)location.reload();return}if(typeof m.version==='number')version=m.version;if(m.type==='reload')location.reload();else if(m.type==='css')bust();else if(m.type==='fragment')swapFragment();else if(m.type==='store')reloadStores();else if(m.type==='build-error')__stxOverlay(m.errors)}catch(_){}};source.onerror=function(){if(es===source&&source.readyState===2){setTimeout(function(){location.reload()},400)}}}connect();addEventListener('pagehide',function(){if(es){es.close();es=null}});addEventListener('pageshow',function(e){if(e.persisted&&!es)connect()})})()</script>`;
|
|
9379
9382
|
function injectHmrClient(html) {
|
|
9380
9383
|
if (!html || production)
|
|
9381
9384
|
return html;
|
|
9382
9385
|
refreshBuildErrors();
|
|
9386
|
+
const client = HMR_CLIENT_SCRIPT.replace("__STX_HMR_VERSION__", String(hmrVersion));
|
|
9383
9387
|
const closeBody = html.lastIndexOf("</body>");
|
|
9384
9388
|
if (closeBody === -1) {
|
|
9385
|
-
return html +
|
|
9389
|
+
return html + client;
|
|
9386
9390
|
}
|
|
9387
|
-
return html.slice(0, closeBody) +
|
|
9391
|
+
return html.slice(0, closeBody) + client + html.slice(closeBody);
|
|
9388
9392
|
}
|
|
9389
9393
|
let currentBuildErrors = [];
|
|
9390
9394
|
async function refreshBuildErrors() {
|
|
@@ -10531,7 +10535,7 @@ ${block}`;
|
|
|
10531
10535
|
start(c) {
|
|
10532
10536
|
controller = c;
|
|
10533
10537
|
hmrClients.add(c);
|
|
10534
|
-
c.enqueue(hmrEncoder.encode(`data: {"type":"connected"}
|
|
10538
|
+
c.enqueue(hmrEncoder.encode(`data: {"type":"connected","version":${hmrVersion}}
|
|
10535
10539
|
|
|
10536
10540
|
`));
|
|
10537
10541
|
if (currentBuildErrors.length > 0) {
|
package/package.json
CHANGED