Skip to content

Read the thread TOC breakpoint off the ResizeObserver entry - #1912

Merged
SawyerHood merged 1 commit into
get-bb:mainfrom
ebg1223:pr/thread-toc-resize-observer
Aug 19, 2026
Merged

SawyerHood merged 1 commit into
get-bb:mainfrom
ebg1223:pr/thread-toc-resize-observer

Conversation

@ebg1223

@ebg1223 ebg1223 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

useThreadTocVisible measured the scroll overlay with getComputedStyle(host) plus clientWidth, inside a requestAnimationFrame callback. rAF runs before the frame's style and layout phase, so that pairing forced a full-document style recalculation every time it fired — 750ms per call on one profiled thread, and 67% of all script time on another. The resulting setVisible re-triggered the observer, which is the "ResizeObserver loop completed with undelivered notifications" warning seen in the console.

The observer entry already carries the number: contentBoxSize[0].inlineSize is exactly what an inline-size container query resolves against, so the padding correction the old code reconstructed by hand comes for free. ResizeObserver callbacks run after layout, so reading the entry costs nothing and the animation-frame hop is unnecessary. containerInlineSize is deleted.

Behavior on display:none is unchanged — a box-less element gets no entry, so visibility stays false exactly as the old clientWidth === 0 path did, and the observer fires normally once the element is shown.

The test's ResizeObserverMock now models the platform instead: observe() delivers the target's current content box (border box minus horizontal padding). The three breakpoint tests still assert the same numbers, 876px hidden and 896px shown.

useThreadTocVisible measured the scroll overlay with
`getComputedStyle(host)` plus `clientWidth`, inside a requestAnimationFrame
callback. rAF runs before the frame's style and layout phase, so that pairing
forced a full-document style recalculation every time it fired — 750ms per
call on one profiled thread, and 67% of all script time on another. The
resulting setVisible re-triggered the observer, which is the "ResizeObserver
loop completed with undelivered notifications" warning seen in the console.

The observer entry already carries the number: contentBoxSize[0].inlineSize
is exactly what an inline-size container query resolves against, so the
padding correction the old code reconstructed by hand comes for free.
ResizeObserver callbacks run after layout, so reading the entry costs nothing
and the animation-frame hop is unnecessary. containerInlineSize is deleted.

Behavior on display:none is unchanged — a box-less element gets no entry, so
visibility stays false exactly as the old clientWidth === 0 path did, and the
observer fires normally once the element is shown.

The test's ResizeObserverMock now models the platform instead: observe()
delivers the target's current content box (border box minus horizontal
padding). The three breakpoint tests still assert the same numbers, 876px
hidden and 896px shown.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain English summary: This pull request uses size data that the browser already supplies. It aims to remove a slow layout measurement from the thread contents panel.

I am the SlopCop, and I am reviewing this change now. I will check security, code quality, performance, tests, duplicate code, and the architecture.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain English summary: This pull request stops measuring the thread contents panel during a frame. It uses the content-box size that the browser already provides.

I found no issue that needs a change.

  • Security: The change adds no new input or trust boundary. The observer callback only reads browser layout data.
  • Code quality: The hook has a clear lifetime, handles a missing entry, and disconnects the observer during cleanup.
  • Performance: The change removes getComputedStyle, clientWidth, and the animation-frame callback from this resize path. This removes the forced-layout work that the pull request targets.
  • Tests: The focused suite passed all 22 tests. The Turbo app type check and git diff --check also passed. All current GitHub CI checks passed.
  • Browser check: The source app loaded at the exact head commit in headless Chromium with no page errors. The empty development account had no thread, so I could not exercise the TOC breakpoint through the full interface.
  • Architecture: The codebase scan found no duplicate TOC breakpoint logic. Other ResizeObserver users measure different boxes or states. A shared helper is not justified here.

One old-browser note is not actionable for this product. Early WebKit versions can omit contentBoxSize, but those versions also cannot display this container-query TOC. The existing contentRect fallback remains useful after a defensive optional-property guard, but I do not require that change.

The quoted Safari timing values were not reproduced. The code inspection still confirms removal of the synchronous layout reads.

@SawyerHood
SawyerHood merged commit 0f6759a into get-bb:main Aug 19, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants