From ee41f361b6d9f2df6f6440c6dea8ce5703c28f50 Mon Sep 17 00:00:00 2001 From: David Montero Date: Sun, 7 Jun 2026 02:13:58 +0200 Subject: [PATCH] fix(frontend): don't clobber a project's saved library manifest on save MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit buildSavePayload omitted libraries_json=[] whenever the manifest store was empty — so an autosave right after loading a project (whose manifest the store hadn't restored) wiped the saved manifest. Now omit libraries_json entirely when the store value is null (unknown), so the backend preserves the saved manifest. The compiler reads it server-side regardless (get_project_libraries hook). --- frontend/src/utils/projectPayload.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/utils/projectPayload.ts b/frontend/src/utils/projectPayload.ts index 674a930c..69533a5c 100644 --- a/frontend/src/utils/projectPayload.ts +++ b/frontend/src/utils/projectPayload.ts @@ -97,6 +97,13 @@ export function buildSavePayload(meta: SnapshotInputs = {}): ProjectSaveData { })); const fileGroups = [...boardGroups, ...chipGroups]; + // P2.4 — declared library manifest (compile scope). Persist it ONLY when it + // is explicitly known (non-null). null means "unknown" — e.g. a reloaded + // project whose manifest wasn't restored into the store — so we OMIT the + // field and the backend preserves the saved manifest instead of clobbering + // it to []. The compiler reads the saved manifest server-side regardless. + const manifestLibs = useLibraryManifestStore.getState().libraries; + return { name: meta.name ?? '', description: meta.description, @@ -108,9 +115,7 @@ export function buildSavePayload(meta: SnapshotInputs = {}): ProjectSaveData { components_json: JSON.stringify(sim.components), wires_json: JSON.stringify(sim.wires), boards_json: JSON.stringify(sim.boards.map(serialisableBoard)), - // P2.4 — persist the declared library manifest (compile scope) so reloading - // the project re-sends it. Empty when the project declares no libraries. - libraries_json: JSON.stringify(useLibraryManifestStore.getState().libraries ?? []), + ...(manifestLibs !== null ? { libraries_json: JSON.stringify(manifestLibs) } : {}), }; }