Skip to content

Commit 3cbc6ed

Browse files
authored
Clear stale SeqJSON output when switching workspace files (#1889)
* clear stale SeqJSON output when switching workspace files * show SeqJSON output for untitled sequence files On initial page load with no file selected, the SeqJSON output pane was empty because no output computation was triggered on mount. Also, typing in an untitled sequence cleared the output because Svelte 4 bypasses prop defaults on reactive updates (has bitten us before). Passing undefined from the parent set sequenceName to undefined instead of the default ''.
1 parent 5f9e947 commit 3cbc6ed

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/components/sequencing/SequenceEditor.svelte

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@
176176
debouncedOutputUpdate.cancel();
177177
dispatchLintChange.cancel();
178178
previousSequenceFilePath = sequenceFilePath;
179+
180+
// Clear stale output and recompute for the new file
181+
if (editorOutputView) {
182+
editorOutputView.dispatch({ changes: { from: 0, insert: '', to: editorOutputView.state.doc.length } });
183+
debouncedOutputUpdate(editorSequenceView?.state.doc.toString() ?? '');
184+
}
179185
}
180186
181187
function sequenceUpdateListener(viewUpdate: ViewUpdate): void {
@@ -194,12 +200,8 @@
194200
if (!preserveAdaptationLog) {
195201
clearWorkspaceAdaptationMessages();
196202
}
197-
198203
try {
199-
output =
200-
sequenceName === undefined
201-
? undefined
202-
: selectedOutputFormat?.toOutputFormat?.(sequence, phoenixContext, sequenceName);
204+
output = selectedOutputFormat?.toOutputFormat?.(sequence, phoenixContext, sequenceName);
203205
} catch (e) {
204206
console.error('Adaptation toOutputFormat error:', e);
205207
if (sequenceFilePath) {
@@ -364,6 +366,9 @@
364366
],
365367
parent: editorOutputDiv,
366368
});
369+
370+
// Compute initial output for the starting content (e.g., untitled empty sequence on page load)
371+
debouncedOutputUpdate(editorSequenceView.state.doc.toString());
367372
});
368373
369374
onDestroy(() => {

src/routes/workspaces/[workspaceId]/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
}
337337
338338
// successfully navigated, start loading the file contents
339+
selectedSequenceOutput = undefined;
339340
if (nextPath && workspaceTreeMap[nextPath]) {
340341
const { filename } = separateFilenameFromPath(nextPath);
341342
const fileType = workspaceTreeMap[nextPath]?.type ?? null;
@@ -1054,7 +1055,7 @@
10541055
previewOnly={!hasEditFilePermission}
10551056
sequenceAdaptation={$sequenceAdaptation}
10561057
sequenceDefinition={$activeDocument.originalContent}
1057-
sequenceName={$activeDocument.fileName ?? undefined}
1058+
sequenceName={$activeDocument.fileName ?? ''}
10581059
sequenceFilePath={$activeDocumentPath ?? ''}
10591060
sequenceOutput={selectedSequenceOutput}
10601061
shouldListenForKeyboardSave={false}
@@ -1080,7 +1081,7 @@
10801081
isLoading={$activeDocumentIsLoading}
10811082
previewOnly={!hasEditFilePermission}
10821083
shouldListenForKeyboardSave={false}
1083-
textFileName={$activeDocument.fileName ?? undefined}
1084+
textFileName={$activeDocument.fileName ?? ''}
10841085
textFilePath={$activeDocumentPath ?? ''}
10851086
textFileContent={$activeDocument.originalContent}
10861087
on:lintChange={onLintChange}

0 commit comments

Comments
 (0)