Skip to content

Commit e17b8b5

Browse files
committed
fix widget interaction suspend/resume firing too eagerly, causing dropdowns to not show up in certain cases
1 parent 13b7284 commit e17b8b5

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

app/gui/src/project-view/providers/widgetRegistry/__tests__/editHandler.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ function editHandlerTree(
2525
}
2626
const portId = id as PortId
2727
const interaction = createInteraction(portId)
28+
const instanceId = newWidgetInstanceId()
2829
const handler = WidgetEditHandler.NewRaw(
29-
newWidgetInstanceId(),
30+
() => instanceId,
3031
() => portId,
3132
() => (parent ? handlers.get(parent)?.handler : undefined),
3233
interaction,

app/gui/src/project-view/providers/widgetRegistry/editHandler.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,7 @@ import { WidgetInput, WidgetTypeId } from '@/providers/widgetRegistry'
55
import { injectWidgetTree, type CurrentEdit } from '@/providers/widgetTree'
66
import type { Ast } from '@/util/ast'
77
import { ArgumentInfoKey } from '@/util/callTree'
8-
import { ToValue } from '@/util/reactivity'
9-
import {
10-
computed,
11-
markRaw,
12-
shallowRef,
13-
toValue,
14-
useId,
15-
watch,
16-
watchEffect,
17-
WatchSource,
18-
type ShallowRef,
19-
} from 'vue'
8+
import { computed, markRaw, shallowRef, useId, watch, WatchSource, type ShallowRef } from 'vue'
209
import { assertDefined } from 'ydoc-shared/util/assert'
2110

2211
declare const widgetInstanceIdBrand: unique symbol
@@ -271,7 +260,7 @@ export class WidgetEditHandler extends WidgetEditHandlerParent {
271260

272261
/** Create {@link WidgetEditHandler} by manually providing all needed inputs. Useful for testing. */
273262
static NewRaw(
274-
widgetInstanceId: ToValue<WidgetInstanceId>,
263+
widgetInstanceId: WatchSource<WidgetInstanceId>,
275264
portId: WatchSource<PortId>,
276265
parent: WatchSource<WidgetEditHandlerParent | undefined>,
277266
myInteraction: WidgetEditHooks,
@@ -294,13 +283,14 @@ export class WidgetEditHandler extends WidgetEditHandlerParent {
294283
{ immediate: true },
295284
)
296285
assertDefined(currentHandler.value)
297-
watchEffect((onCleanup) => {
298-
const handler = currentHandler.value
299-
const id = toValue(widgetInstanceId)
300-
handler.tryResume(id, handler.portId)
301-
onCleanup(() => handler.suspend(id))
302-
})
303-
286+
watch(
287+
[currentHandler, widgetInstanceId],
288+
([handler, id], _, onCleanup) => {
289+
handler.tryResume(id, handler.portId)
290+
onCleanup(() => handler.suspend(id))
291+
},
292+
{ immediate: true },
293+
)
304294
return currentHandler
305295
}
306296

0 commit comments

Comments
 (0)