Skip to content

Commit 238b27a

Browse files
committed
fix error state on navigating to preview
1 parent 7f9c03a commit 238b27a

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

web-common/src/features/canvas/CanvasInitialization.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
3434
$: ({ url } = $page);
3535
36-
$: existingStore = getCanvasStoreUnguarded(canvasName, instanceId);
36+
$: existingStore = getCanvasStoreUnguarded(
37+
canvasName,
38+
instanceId,
39+
allowUnvalidatedSpec,
40+
);
3741
3842
$: fetchedCanvasQuery = !existingStore
3943
? createQueryServiceResolveCanvas(

web-common/src/features/canvas/state-managers/state-managers.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ function makeCanvasId(canvasName: string, instanceId: string): CanvasId {
2121
export function getCanvasStoreUnguarded(
2222
canvasName: string,
2323
instanceId: string,
24+
allowUnvalidatedSpec?: boolean,
2425
): CanvasStore | undefined {
2526
const id = makeCanvasId(canvasName, instanceId);
27+
const store = canvasRegistry.get(id);
28+
29+
if (
30+
store &&
31+
allowUnvalidatedSpec !== undefined &&
32+
store.canvasEntity.allowUnvalidatedSpec !== allowUnvalidatedSpec
33+
) {
34+
store.canvasEntity.unsubscribe();
35+
canvasRegistry.delete(id);
36+
return undefined;
37+
}
2638

27-
return canvasRegistry.get(id);
39+
return store;
2840
}
2941

3042
export function getCanvasStore(
@@ -65,11 +77,18 @@ export function setCanvasStore(
6577
): CanvasStore {
6678
const id = makeCanvasId(canvasName, instanceId);
6779

68-
if (canvasRegistry.has(id)) {
80+
const existingStore = canvasRegistry.get(id);
81+
if (
82+
existingStore &&
83+
existingStore.canvasEntity.allowUnvalidatedSpec !== allowUnvalidatedSpec
84+
) {
85+
existingStore.canvasEntity.unsubscribe();
86+
canvasRegistry.delete(id);
87+
} else if (existingStore) {
6988
console.warn(
7089
`Canvas store for ID ${id} already exists. Returning existing store.`,
7190
);
72-
return canvasRegistry.get(id)!;
91+
return existingStore;
7392
}
7493

7594
const canvasEntity = new CanvasEntity(

0 commit comments

Comments
 (0)