From ed9607e9e86823b00d97f9cdb221d965ded32e2a Mon Sep 17 00:00:00 2001 From: ginnoir Date: Thu, 11 Jun 2026 21:23:18 -0500 Subject: [PATCH] refactor(state): address HMR and defensive slicing recommendations for runtime --- src/state/runtime.ts | 11 ++++++++++- src/state/storyOrchestration.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/state/runtime.ts b/src/state/runtime.ts index d907322..aae47e6 100644 --- a/src/state/runtime.ts +++ b/src/state/runtime.ts @@ -87,6 +87,7 @@ export class GameRuntime { } document.removeEventListener('visibilitychange', this.visibilityChangeListener); window.removeEventListener('beforeunload', this.beforeUnloadListener); + this.booted = false; } performAction(actionId: string): void { @@ -196,7 +197,9 @@ export class GameRuntime { const store = useGameStore.getState(); for (const entry of entries) store.appendStoryLog(entry); for (const entry of entries) { - store.appendLog(`Story: ${content.storyNodesById[entry.nodeId]?.prose.slice(0, 40)}…`); + store.appendLog( + `Story: ${(content.storyNodesById[entry.nodeId]?.prose ?? '').slice(0, 40)}…`, + ); } const prefs = store.prefs; if (shouldAutoNavigateToStory(prefs, 'fork_choice', content)) { @@ -295,3 +298,9 @@ export class GameRuntime { } export const gameRuntime = new GameRuntime(); + +if (import.meta.hot) { + import.meta.hot.dispose(() => { + gameRuntime.stop(); + }); +} diff --git a/src/state/storyOrchestration.ts b/src/state/storyOrchestration.ts index 56f0568..6ce4537 100644 --- a/src/state/storyOrchestration.ts +++ b/src/state/storyOrchestration.ts @@ -46,7 +46,7 @@ export function processStoryTriggers( ...logEntries.map((e) => e.choiceLabel ? `Story: ${e.choiceLabel}` - : `Story: ${content.storyNodesById[e.nodeId]?.prose.slice(0, 40)}…`, + : `Story: ${(content.storyNodesById[e.nodeId]?.prose ?? '').slice(0, 40)}…`, ), ]; return { enteredNodeIds, logEntries, shouldOpenPanel, eventLogLines };