From 8c8afaba698e7ce18f14d58133abaeff5bd13116 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 10 Mar 2026 23:55:32 -0400 Subject: [PATCH] fix file new/open clearing and rebuilding state --- src/void/api/document.js | 4 +++- src/void/api/solids.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/void/api/document.js b/src/void/api/document.js index 877e5f70..6affb70c 100644 --- a/src/void/api/document.js +++ b/src/void/api/document.js @@ -331,6 +331,7 @@ function createDocumentApi(getApi, cfg) { createAndSelect() { this.create(); this.hydrateRuntimeState(this.current); + getApi().solids?.onDocumentHydrated?.('document.new'); return this.save({ kind: 'major', opType: 'snapshot', @@ -360,6 +361,7 @@ function createDocumentApi(getApi, cfg) { return null; } this._redoStack = []; + api.solids?.onDocumentHydrated?.('document.open'); return Promise.all([ api.db.admin.put(ADMIN_CURRENT_DOC_KEY, this.current.id), api.db.admin.put(ADMIN_CURRENT_REV_KEY, this.current.head_rev || null) @@ -427,7 +429,7 @@ function createDocumentApi(getApi, cfg) { this.current.head_rev = revision.rev_id || this.revisionKey(this.current.id, this.current.version); this.current.modified_at = revision.created_at || this.current.modified_at || Date.now(); this.hydrateRuntimeState(this.current); - api.solids?.scheduleRebuild?.('document.hydrate'); + api.solids?.onDocumentHydrated?.('document.hydrate'); return Promise.all([ api.db.documents.put(this.current.id, this.current), api.db.admin.put(ADMIN_CURRENT_DOC_KEY, this.current.id), diff --git a/src/void/api/solids.js b/src/void/api/solids.js index a7f221e3..4f757827 100644 --- a/src/void/api/solids.js +++ b/src/void/api/solids.js @@ -1003,6 +1003,25 @@ function edgeKey(a, b) { world?.add?.(this._root); }, + onDocumentHydrated(reason = 'document.hydrate', options = {}) { + clearTimeout(this._rebuildTimer); + this._pendingReason = null; + // Invalidate any in-flight rebuild response from prior document state. + this._rebuildSeq++; + this._meshCache = new Map(); + this._selectedIds.clear(); + this._hoveredIds.clear(); + this._selectedFaceKeys.clear(); + this._hoveredFaceKey = null; + this._selectedEdgeKeys.clear(); + this._hoveredEdgeKey = null; + this._frozenChamferEdges = null; + this.syncRuntime(); + if (options?.rebuild !== false) { + this.scheduleRebuild(reason, 0); + } + }, + getSketchDerivedBoundarySegmentsForSolid(solid) { const api = getApi(); if (!solid || String(solid?.source?.feature_type || '') !== 'extrude') return [];