@@ -420,6 +420,14 @@ export function Sidebar() {
420420 return fallback ;
421421 }
422422 } ) ;
423+ const persistSelectedSimulationRef = ( ref : string ) => {
424+ setSelectedSimulationRef ( ref ) ;
425+ try {
426+ localStorage . setItem ( LAST_SIMULATION_REF_KEY , ref ) ;
427+ } catch {
428+ // ignore
429+ }
430+ } ;
423431 const [ startupSimulationApplied , setStartupSimulationApplied ] = useState ( false ) ;
424432 const [ storageImportMode , setStorageImportMode ] = useState < "merge" | "replace" > ( "merge" ) ;
425433 const [ storageStatus , setStorageStatus ] = useState ( "" ) ;
@@ -554,12 +562,7 @@ export function Sidebar() {
554562 const exists = simulationPresets . some ( ( preset ) => preset . id === presetId ) ;
555563 if ( ! exists ) {
556564 const fallback = `builtin:${ selectedScenarioId } ` ;
557- setSelectedSimulationRef ( fallback ) ;
558- try {
559- localStorage . setItem ( LAST_SIMULATION_REF_KEY , fallback ) ;
560- } catch {
561- // ignore
562- }
565+ persistSelectedSimulationRef ( fallback ) ;
563566 }
564567 }
565568 } , [ selectedSimulationRef , simulationPresets , selectedScenarioId ] ) ;
@@ -935,12 +938,7 @@ export function Sidebar() {
935938 const savedId = saveCurrentSimulationPreset ( trimmed ) ;
936939 if ( savedId ) {
937940 const ref = `saved:${ savedId } ` ;
938- setSelectedSimulationRef ( ref ) ;
939- try {
940- localStorage . setItem ( LAST_SIMULATION_REF_KEY , ref ) ;
941- } catch {
942- // ignore
943- }
941+ persistSelectedSimulationRef ( ref ) ;
944942 setSimulationSaveStatus ( `Saved simulation: ${ trimmed } ` ) ;
945943 }
946944 setNewPresetName ( "" ) ;
@@ -2338,7 +2336,7 @@ export function Sidebar() {
23382336 className = "inline-action"
23392337 onClick = { ( ) => {
23402338 loadSimulationPreset ( preset . id ) ;
2341- setSelectedSimulationRef ( `saved:${ preset . id } ` ) ;
2339+ persistSelectedSimulationRef ( `saved:${ preset . id } ` ) ;
23422340 } }
23432341 type = "button"
23442342 >
0 commit comments