Ensure the LoadPreferences message is dispatched with None when no preferences exist (#3198)

* preference load message on default load

* review fixup
This commit is contained in:
Timon
2025-09-23 20:19:16 +00:00
committed by GitHub
parent 21f34ab19a
commit d15f63f4fd
6 changed files with 18 additions and 15 deletions
+1 -3
View File
@@ -147,9 +147,7 @@ export function createPersistenceManager(editor: Editor, portfolio: PortfolioSta
async function loadPreferences() {
const preferences = await get<Record<string, unknown>>("preferences", graphiteStore);
if (!preferences) return;
editor.handle.loadPreferences(JSON.stringify(preferences));
editor.handle.loadPreferences(preferences ? JSON.stringify(preferences) : undefined);
}
// FRONTEND MESSAGE SUBSCRIPTIONS
+9 -5
View File
@@ -421,14 +421,18 @@ impl EditorHandle {
}
#[wasm_bindgen(js_name = loadPreferences)]
pub fn load_preferences(&self, preferences: String) {
let Ok(preferences) = serde_json::from_str(&preferences) else {
log::error!("Failed to deserialize preferences");
return;
pub fn load_preferences(&self, preferences: Option<String>) {
let preferences = if let Some(preferences) = preferences {
let Ok(preferences) = serde_json::from_str(&preferences) else {
log::error!("Failed to deserialize preferences");
return;
};
Some(preferences)
} else {
None
};
let message = PreferencesMessage::Load { preferences };
self.dispatch(message);
}