sandboxedjs 0.1.43 → 0.1.45
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/index.cjs +18 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/service-worker.js +67 -2
- package/dist/service-worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1451,6 +1451,20 @@ interface PreviewOptions {
|
|
|
1451
1451
|
scriptUrl?: string | URL;
|
|
1452
1452
|
/** Registration scope. Must be able to see the paths a preview will request. */
|
|
1453
1453
|
scope?: string;
|
|
1454
|
+
/**
|
|
1455
|
+
* The dev server has invalidated what the frame is holding; reload it.
|
|
1456
|
+
*
|
|
1457
|
+
* Vite serves `504 Outdated Optimize Dep` once the hash in a dependency URL
|
|
1458
|
+
* no longer matches — after its optimizer re-runs, or after the server is
|
|
1459
|
+
* restarted. Its own client recovers by reloading, and hears about it over
|
|
1460
|
+
* the HMR WebSocket, which this bridge does not carry. Without a reload the
|
|
1461
|
+
* frame keeps asking for a hash the server has forgotten and the app never
|
|
1462
|
+
* mounts.
|
|
1463
|
+
*
|
|
1464
|
+
* Reloading is the host's call because the host owns the frame: it can pick
|
|
1465
|
+
* the moment, and it can stop after a few attempts rather than looping.
|
|
1466
|
+
*/
|
|
1467
|
+
onStale?: () => void;
|
|
1454
1468
|
}
|
|
1455
1469
|
interface Preview {
|
|
1456
1470
|
/** The URL an iframe should be pointed at to see `port`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1451,6 +1451,20 @@ interface PreviewOptions {
|
|
|
1451
1451
|
scriptUrl?: string | URL;
|
|
1452
1452
|
/** Registration scope. Must be able to see the paths a preview will request. */
|
|
1453
1453
|
scope?: string;
|
|
1454
|
+
/**
|
|
1455
|
+
* The dev server has invalidated what the frame is holding; reload it.
|
|
1456
|
+
*
|
|
1457
|
+
* Vite serves `504 Outdated Optimize Dep` once the hash in a dependency URL
|
|
1458
|
+
* no longer matches — after its optimizer re-runs, or after the server is
|
|
1459
|
+
* restarted. Its own client recovers by reloading, and hears about it over
|
|
1460
|
+
* the HMR WebSocket, which this bridge does not carry. Without a reload the
|
|
1461
|
+
* frame keeps asking for a hash the server has forgotten and the app never
|
|
1462
|
+
* mounts.
|
|
1463
|
+
*
|
|
1464
|
+
* Reloading is the host's call because the host owns the frame: it can pick
|
|
1465
|
+
* the moment, and it can stop after a few attempts rather than looping.
|
|
1466
|
+
*/
|
|
1467
|
+
onStale?: () => void;
|
|
1454
1468
|
}
|
|
1455
1469
|
interface Preview {
|
|
1456
1470
|
/** The URL an iframe should be pointed at to see `port`. */
|
package/dist/index.js
CHANGED
|
@@ -28794,9 +28794,21 @@ async function createPreview(box, options = {}) {
|
|
|
28794
28794
|
});
|
|
28795
28795
|
if (!activated) return null;
|
|
28796
28796
|
}
|
|
28797
|
-
|
|
28798
|
-
|
|
28799
|
-
|
|
28797
|
+
let channel = null;
|
|
28798
|
+
const connect = () => {
|
|
28799
|
+
channel?.port1.close();
|
|
28800
|
+
channel = new MessageChannel();
|
|
28801
|
+
serveContainerOn(channel.port1, box);
|
|
28802
|
+
const target = registration.active ?? worker;
|
|
28803
|
+
target.postMessage({ type: "sandboxedjs:connect" }, [channel.port2]);
|
|
28804
|
+
};
|
|
28805
|
+
const onWorkerMessage = (event) => {
|
|
28806
|
+
const type = event.data?.type;
|
|
28807
|
+
if (type === "sandboxedjs:host-needed") connect();
|
|
28808
|
+
if (type === "sandboxedjs:stale") options.onStale?.();
|
|
28809
|
+
};
|
|
28810
|
+
navigator.serviceWorker.addEventListener("message", onWorkerMessage);
|
|
28811
|
+
connect();
|
|
28800
28812
|
const base2 = registration.scope.replace(/\/$/, "");
|
|
28801
28813
|
const urlFor = (port) => `${base2}/__sbx__/${port}/`;
|
|
28802
28814
|
return {
|
|
@@ -28809,7 +28821,9 @@ async function createPreview(box, options = {}) {
|
|
|
28809
28821
|
return `${urlFor(target.port).replace(/\/$/, "")}${path}`;
|
|
28810
28822
|
},
|
|
28811
28823
|
dispose: async () => {
|
|
28812
|
-
|
|
28824
|
+
navigator.serviceWorker.removeEventListener("message", onWorkerMessage);
|
|
28825
|
+
channel?.port1.close();
|
|
28826
|
+
channel = null;
|
|
28813
28827
|
await registration.unregister();
|
|
28814
28828
|
}
|
|
28815
28829
|
};
|