Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/stores/widgetValueStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ describe('useWidgetValueStore', () => {
expect(second.value).toBe(99)
})

it('replaces a stale entry when the widget type changes', () => {
const store = useWidgetValueStore()
const first = store.registerWidget(seedA, state('number', 5))!
first.value = 42

// After a subgraph convert the graphId:nodeId:name key can be reused by a
// different widget. A type mismatch means it is not the same widget, so
// the live type/value must win rather than the stale entry (BUG: a text
// widget rendered as int until reload).
const reconciled = store.registerWidget(seedA, state('string', 'hello'))!
expect(reconciled.type).toBe('string')
expect(reconciled.value).toBe('hello')
expect(store.getWidget(seedA)?.type).toBe('string')
})

it('registers a widget with all properties', () => {
const store = useWidgetValueStore()
const registered = store.registerWidget(
Expand Down
4 changes: 3 additions & 1 deletion src/stores/widgetValueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const useWidgetValueStore = defineStore('widgetValue', () => {
}

const existing = getWidget(widgetId)
if (existing) return existing as WidgetState<TValue>
if (existing && existing.type === init.type) {
return existing as WidgetState<TValue>
}

const { graphId, nodeId, name } = parseWidgetId(widgetId)
const state: WidgetState<TValue> = {
Expand Down
Loading