From 22352bc43c0ae7423706a7c17bfa38b024ea011f Mon Sep 17 00:00:00 2001 From: John Rogers Date: Thu, 24 Sep 2026 14:44:43 +0100 Subject: [PATCH] Keep instrument refs on live results when sharing or saving prepForFireStore deleted question.instrument from the live apiData before cloning it for Firestore, because makePublicShareLink and saveToMyHarmony pass the state object straight in. After a share or save, every question lost its instrument, so the next Excel export threw at q.instrument.name (App.js downloadExcel) until the user re-ran the match. That made the failure look sporadic. Drop the reference while cloning instead, as meta's harmonyFirestore does. The stored payload is unchanged. Co-Authored-By: Claude Opus 5.5 --- src/contexts/DataContext.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/contexts/DataContext.js b/src/contexts/DataContext.js index a861be2..65df43f 100644 --- a/src/contexts/DataContext.js +++ b/src/contexts/DataContext.js @@ -300,14 +300,14 @@ export function DataProvider({ children }) { return addDoc(collection(db, "mismatches"), m); }; const prepForFireStore = (harmonisation) => { - harmonisation.apiData.instruments.map((instrument) => - instrument.questions.map( - (question) => - //This is a circular reference but can't be stored - delete question["instrument"] + //question.instrument is a circular reference so can't be stored; drop it + //from a copy rather than deleting it from the live apiData, which the + //results page (and Excel export) still rely on after a share or save + harmonisation.apiData = JSON.parse( + JSON.stringify(harmonisation.apiData, (key, value) => + key === "instrument" ? undefined : value ) ); - harmonisation.apiData = JSON.parse(JSON.stringify(harmonisation.apiData)); console.log("prepped"); console.log(harmonisation); return harmonisation;