Skip to content

Commit 5b43034

Browse files
committed
Update scroll data in timeout (fixes #307)
1 parent 5afa738 commit 5b43034

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

.changeset/healthy-doors-beam.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@solid-devtools/frontend": patch
3+
---
4+
5+
Update scroll data in timeout, after the ResizeObserver callback
6+
To prevent this error:
7+
> ResizeObserver loop completed with undelivered notifications
8+
As changing scroll data can then change el.scrollTop
9+
Fixes #307

packages/frontend/src/structure.tsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,21 @@ const getFocusedNodeData = (
495495
}
496496

497497
const DisplayStructureTree: s.Component = () => {
498-
const [containerScroll, setContainerScroll] = s.createSignal({top: 0, height: 0})
498+
499+
const [containerScroll, setContainerScroll] = s.createSignal({
500+
top: 0,
501+
height: 0,
502+
}, {
503+
equals: (a, b) => a.top === b.top && a.height === b.height
504+
})
499505

500506
const remSize = useRemSize()
501-
const getContainerTopMargin = (): number => remSize() * v_margin_in_rem
502-
const getRowHeight = (): number => remSize() * row_height_in_rem
507+
const getContainerTopMargin = () => remSize() * v_margin_in_rem
508+
const getRowHeight = () => remSize() * row_height_in_rem
503509

504510
const updateScrollData = (el: HTMLElement): void => {
505511
setContainerScroll({
506-
top: Math.max(el.scrollTop - getContainerTopMargin(), 0),
512+
top: Math.max(el.scrollTop - getContainerTopMargin(), 0),
507513
height: el.clientHeight,
508514
})
509515
}
@@ -621,16 +627,14 @@ const DisplayStructureTree: s.Component = () => {
621627
})
622628

623629
// Seep the inspected or central node in view when the list is changing
624-
s.createEffect(
625-
defer(collapsedList, () => {
626-
if (!lastFocusedNodeData) return
627-
const [nodeId, lastPosition] = lastFocusedNodeData
628-
const index = getNodeIndexById(nodeId)
629-
if (index === -1) return
630-
const move = index - virtual().start - lastPosition
631-
if (move !== 0) container.scrollTop += move * getRowHeight()
632-
}),
633-
)
630+
s.createEffect(defer(collapsedList, () => {
631+
if (!lastFocusedNodeData) return
632+
const [nodeId, lastPosition] = lastFocusedNodeData
633+
const index = getNodeIndexById(nodeId)
634+
if (index === -1) return
635+
const move = index - virtual().start - lastPosition
636+
if (move !== 0) container.scrollTop += move * getRowHeight()
637+
}))
634638

635639
// Scroll to selected node when it changes
636640
// listen to inspected ID, instead of node, because node reference can change
@@ -752,8 +756,17 @@ const DisplayStructureTree: s.Component = () => {
752756
<ui.Scrollable
753757
ref={el => {
754758
container = el
755-
setTimeout(() => updateScrollData(el))
756-
createResizeObserver(el, () => updateScrollData(el))
759+
createResizeObserver(el, () => {
760+
/*
761+
Update data in timeout, after the ResizeObserver callback
762+
To prevent this error:
763+
> ResizeObserver loop completed with undelivered notifications
764+
As changing scroll data can then change el.scrollTop
765+
*/
766+
setTimeout(() => {
767+
updateScrollData(el)
768+
})
769+
})
757770
}}
758771
onScroll={e => updateScrollData(e.currentTarget)}
759772
>

0 commit comments

Comments
 (0)