Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance runtime document management and error handling

konstantin-paulusae21a34b7c0c
diff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.ts
index 4c7f5cf5..2e42f23e 100644
--- a/packages/reconciler/src/document.ts
+++ b/packages/reconciler/src/document.ts
@@ -1429,6 +1429,11 @@ export class RuntimeDocument implements ProjectDocument<HostNode> {
public dispose(): void {
this.removeNode(this.stage, this.stage);
+ // The world is free for the next mount. A document already replaced by
+ // another leaves the registry as it found it.
+ if (documents.get(this.world) === this) {
+ documents.delete(this.world);
+ }
}
}
@@ -1444,7 +1449,18 @@ export function getRuntimeDocument(world: World): RuntimeDocument {
return document;
}
+/**
+ * The world's runtime document, for the length of one mount. A world holds at
+ * most one: the stage it renders into is a world singleton, so a second
+ * document would append its project's entities alongside the first's, and the
+ * ones already there would be reachable only through the earlier `Mount`.
+ * Dispose the running mount before starting another.
+ */
export function createRuntimeDocument(world: World): RuntimeDocument {
+ if (documents.has(world)) {
+ throw new Error('This world already has a mounted project — dispose it before mounting another');
+ }
+
const document = new RuntimeDocument(world);
documents.set(world, document);
return document;
diff --git a/packages/reconciler/src/mount.ts b/packages/reconciler/src/mount.ts
index ae78d792..11fe66d9 100644
--- a/packages/reconciler/src/mount.ts
+++ b/packages/reconciler/src/mount.ts
@@ -15,7 +15,9 @@ export interface Mount {
/**
* Renders a compiled project bundle into `world`. Throws if the bundle does
- * not evaluate or its root is not a <stage>; nothing is left behind in the
+ * not evaluate, if its root is not a <stage>, or if `world` still has a
+ * mounted project (dispose that one first — the stage is a singleton, so
+ * two mounts would render into each other); nothing is left behind in the
* world when it throws.
*/
export function mount(code: string, world: World): Mount {