@immediately-run/sandpack-client 2.21.1 → 2.22.1

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.
@@ -43,7 +43,7 @@ var GUARDED_WRITE_METHODS = [
43
43
  * (roadmap R3-110).
44
44
  *
45
45
  * This is a module-level function (not a class method) and its **only** reference
46
- * is behind the `if (IS_DEV)` branch in the constructor — so once a consumer's
46
+ * is behind the `if (IS_DEV)` branch in {@link ensureGuard} — so once a consumer's
47
47
  * production build folds `IS_DEV` to `false`, the branch and this whole function
48
48
  * tree-shake away (a class method would be retained). No-op in production.
49
49
  */
@@ -71,6 +71,35 @@ function installOutOfBandGuard(fsContext) {
71
71
  _loop_1(method);
72
72
  }
73
73
  }
74
+ /**
75
+ * The true raw write methods per bound context, captured once and shared by every
76
+ * SandpackFS instance that adopts that context. Without this, a second instance's
77
+ * constructor captures the first instance's wrapper as its "raw" method — because the
78
+ * guard has already replaced `fsContext.fs.promises` entries — so SandpackFS's own
79
+ * writes trip the guard once per prior adoption (the R3-614 stacking bug).
80
+ */
81
+ var RAW = new WeakMap();
82
+ /**
83
+ * Return the context's raw write methods, capturing them and installing the out-of-band
84
+ * guard exactly once per context (see {@link installOutOfBandGuard}). Reads `RAW` first,
85
+ * so adopting the same context any number of times never re-wraps, never re-captures a
86
+ * wrapper as raw, and never disarms a sibling instance.
87
+ */
88
+ function ensureGuard(fsContext) {
89
+ var existing = RAW.get(fsContext);
90
+ if (existing)
91
+ return existing;
92
+ var p = fsContext.fs.promises;
93
+ var raw = {
94
+ writeFile: p.writeFile.bind(p),
95
+ unlink: p.unlink.bind(p),
96
+ mkdir: p.mkdir.bind(p),
97
+ };
98
+ RAW.set(fsContext, raw);
99
+ if (IS_DEV)
100
+ installOutOfBandGuard(fsContext);
101
+ return raw;
102
+ }
74
103
  var mountCounter = 0;
75
104
  var normalize = function (path) {
76
105
  return path.startsWith("/") ? path : "/".concat(path);
@@ -117,12 +146,10 @@ var SandpackFS = /** @class */ (function () {
117
146
  * unmount in {@link dispose}. Unset for an adopted context, whose lifecycle
118
147
  * belongs to the caller. */
119
148
  this.ownedMountPoint = undefined;
120
- var p = fsContext.fs.promises;
121
- this.rawWriteFile = p.writeFile.bind(p);
122
- this.rawUnlink = p.unlink.bind(p);
123
- this.rawMkdir = p.mkdir.bind(p);
124
- if (IS_DEV)
125
- installOutOfBandGuard(fsContext);
149
+ var raw = ensureGuard(fsContext);
150
+ this.rawWriteFile = raw.writeFile;
151
+ this.rawUnlink = raw.unlink;
152
+ this.rawMkdir = raw.mkdir;
126
153
  }
127
154
  /**
128
155
  * Create the `MessagePort` shared with the child iframe, wiring the iframe's
package/dist/types.d.ts CHANGED
@@ -37,6 +37,18 @@ export interface ClientOptions {
37
37
  * `allow-same-origin`). Required for the runtime client to transpile.
38
38
  */
39
39
  babelWorkerURL?: string;
40
+ /**
41
+ * Called when the client REFUSES to register a frame because it booted from a
42
+ * navigation the client did not perform (R3-353 — a sandboxed frame may always
43
+ * navigate itself, and the browsing context survives, so a page the app chose
44
+ * could otherwise post `initialized` and be handed this frame's grants).
45
+ *
46
+ * By the time this fires the frame has been blanked and the client destroyed:
47
+ * nothing was connected and no fs port was minted. The host's job is to surface
48
+ * it (and/or re-create the frame from a clean state), not to decide whether to
49
+ * allow it — that decision has already been made, fail-closed.
50
+ */
51
+ onUnexpectedNavigation?: () => void;
40
52
  /**
41
53
  * Level of logging to do in the bundler
42
54
  */
@@ -239,7 +251,13 @@ export type ClientStatus = "initializing" | "installing-dependencies" | "transpi
239
251
  export type SandpackMessageConsoleMethods = "log" | "debug" | "info" | "warn" | "error" | "table" | "clear" | "time" | "timeEnd" | "count" | "assert";
240
252
  export interface BaseSandpackMessage {
241
253
  type: string;
242
- $id?: number;
254
+ /**
255
+ * The sender's channel id. Newer peers mint it as a crypto-random hex STRING
256
+ * (R3-367 — 64 bits); ids older peers minted as numbers still flow, because
257
+ * each side compares the value it itself sent. Correlation only — never an
258
+ * authenticator (the evt.source check in IFrameProtocol is).
259
+ */
260
+ $id?: string | number;
243
261
  codesandbox?: boolean;
244
262
  /**
245
263
  * Transferable objects (e.g. a `MessagePort`) to hand to the iframe alongside
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immediately-run/sandpack-client",
3
- "version": "2.21.1",
3
+ "version": "2.22.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {