fix(app): stop the ResizeObserver loop error while timeline rows grow (#60481)

This commit is contained in:
Luke Parker
2026-10-30 15:54:37 +10:00
committed by GitHub
Unverified
parent 9425a65eb3
commit e377cf1407
6 changed files with 49 additions and 26 deletions
@@ -50,9 +50,10 @@ export function mountTimelineVirtualizer(input: {
viewport = element
resize.observe(element, { box: "border-box" })
},
setContentRef: (element) => {
content = element
reveal.observe(element, { attributes: true, attributeFilter: ["style"] })
onContentResize: () => {
if (content) return
content = host.querySelector<HTMLDivElement>("[data-timeline-virtual-content]")!
reveal.observe(content, { attributes: true, attributeFilter: ["style"] })
},
onPin: () => setState("pinned", true),
onUnpin: () => setState("pinned", false),
@@ -15,6 +15,7 @@ import {
inboxDelivered,
inboxEnqueued,
messageUpdated,
partDelta,
partUpdated,
reasoningPart,
renderedPartID,
@@ -1010,6 +1011,33 @@ test.describe("Working", () => {
})
})
test("grows a streaming row without a ResizeObserver loop error", async ({ page }) => {
// Each streamed paragraph grows its row. An observer on the content that holds every row saw that height inside the
// row observer's own delivery, and Chrome reported every such frame as an uncaught error.
await page.addInitScript(() => {
window.addEventListener("error", (event) => {
if (!event.message.startsWith("ResizeObserver loop")) return
document.documentElement.dataset.resizeObserverLoops = String(
Number(document.documentElement.dataset.resizeObserverLoops ?? 0) + 1,
)
})
})
const timeline = await setupTimeline(page, {
messages: [userMessage(), assistantMessage([textPart("prt_growth", "Streaming.")], { completed: false })],
})
const text = page.locator(`[data-timeline-part-id="${renderedPartID("prt_growth")}"]`)
for (const line of [1, 2, 3, 4, 5, 6]) {
await timeline.send(partDelta("prt_growth", `\n\nParagraph ${line}.`))
await expect(text).toContainText(`Paragraph ${line}.`)
}
await expect(text.locator("p")).toHaveCount(7)
expect(await page.evaluate(() => document.documentElement.dataset.resizeObserverLoops)).toBeUndefined()
})
test.describe("background shortcut", () => {
test("offers a standalone running subagent to the background with Ctrl+B", async ({ page }) => {
await setupTimeline(page, {
+1 -1
View File
@@ -314,7 +314,7 @@ function SessionScreenContent(props: {
pinned={timeline.view.pinned()}
centered={screen.centered()}
reserveReviewToggle={!sideVisible()}
setContentRef={timeline.view.setContentRef}
onContentResize={timeline.view.contentResized}
bottomInset={timeline.inset()}
setVisibleRef={timeline.view.setVisibleRef}
anchor={timeline.view.anchor}
@@ -23,7 +23,6 @@ export function createSessionTimelineInteraction(session: SessionModel) {
inset: number
refs: {
scroller: HTMLDivElement | undefined
content: HTMLDivElement | undefined
dock: HTMLDivElement | undefined
visible: HTMLDivElement | undefined
}
@@ -41,7 +40,6 @@ export function createSessionTimelineInteraction(session: SessionModel) {
inset: 0,
refs: {
scroller: undefined,
content: undefined,
dock: undefined,
visible: undefined,
},
@@ -361,13 +359,6 @@ export function createSessionTimelineInteraction(session: SessionModel) {
{ defer: true },
),
)
createResizeObserver(
() => state.refs.content,
() => {
if (scroller) scheduleScrollState(scroller)
fill()
},
)
createResizeObserver(
() => state.refs.dock,
(_rect, _element, entry) => {
@@ -426,10 +417,9 @@ export function createSessionTimelineInteraction(session: SessionModel) {
pinned,
selectionInteraction,
scheduleScrollState,
setContentRef: (element: HTMLDivElement | undefined) => {
setState("refs", "content", element)
contentResized: () => {
if (scroller) scheduleScrollState(scroller)
fill()
},
setDockRef: (element: HTMLDivElement | undefined) => {
setState("refs", "dock", element)
@@ -91,7 +91,7 @@ type MessageTimelineProps = {
pinned: boolean
centered: boolean
reserveReviewToggle: boolean
setContentRef: (el: HTMLDivElement) => void
onContentResize: () => void
bottomInset?: number
setVisibleRef?: (el: HTMLDivElement | undefined) => void
anchor: (id: string) => string
@@ -193,7 +193,7 @@ function MessageTimelineView(
scroll: () => props.scroll,
onResumeScroll: props.onResumeScroll,
setScrollRef: props.setScrollRef,
setContentRef: props.setContentRef,
onContentResize: props.onContentResize,
bottomInset: () => props.bottomInset ?? 0,
setVisibleRef: props.setVisibleRef,
onScheduleScrollState: props.onScheduleScrollState,
@@ -75,7 +75,8 @@ type Input = {
scroll: Accessor<{ overflow: boolean; jump: boolean }>
onResumeScroll: (behavior?: ScrollBehavior) => void
setScrollRef: (element: HTMLDivElement | undefined) => void
setContentRef: (element: HTMLDivElement) => void
/** The rows' content changed height. */
onContentResize: () => void
/** Height of the composer region floating over the timeline's bottom edge, where the timeline fades out. */
bottomInset?: Accessor<number>
setVisibleRef?: (element: HTMLDivElement | undefined) => void
@@ -554,8 +555,6 @@ export function createTimelineVirtualizer(input: Input) {
const root = listRoot()
if (root) input.setScrollRef(root)
if (virtualContent) input.setContentRef(virtualContent)
input.setVisibleRef?.(visibleArea())
queueMicrotask(() => {
if (!active() || !root?.isConnected) return
@@ -630,6 +629,15 @@ export function createTimelineVirtualizer(input: Input) {
),
)
// The content is as tall as the rows the virtualizer sizes, so it reports that height rather than the session
// observing the element. A ResizeObserver there sees the height a row's own observer commits during its delivery, and
// Chrome reports every such frame as "ResizeObserver loop completed with undelivered notifications."
createEffect(
on([active, () => virtualizer.getTotalSize() - rendering.scrollAdjustment], () => {
if (active()) input.onContentResize()
}),
)
// Only the viewport carries the inset as a variable, for its fade and scroll padding. The variable does not inherit
// (see index.css): the inset changes on every frame while the composer region grows, and an inherited variable would
// restyle every rendered row each time.
@@ -1030,11 +1038,7 @@ export function createTimelineVirtualizer(input: Input) {
</Show>
<div
data-timeline-virtual-content
ref={(element) => {
virtualContent = element
if (active()) input.setContentRef(element)
}}
ref={virtualContent}
style={{
height: `${virtualizer.getTotalSize() - rendering.scrollAdjustment}px`,
position: "relative",