Load pinned plots that are in view without waiting on a scroll - #940
Conversation
🤖 Claude Code ReviewPR: #940 I have enough context to review. Let me verify the test assertions against the implementation logic once more and check formatting conventions are consistent. The changes are small and focused. Here is my review. Code ReviewOverall this is a clean, well-scoped fix with good test coverage and unusually thorough explanatory comments. It addresses a real bug: pinned plots that were already in view at mount could stay stuck on the loading skeleton because the Correctness
Performance considerations (worth noting, not blocking)
Edge case (minor)
Standards compliance
Nits
Verdict: Looks good to merge. No correctness blockers; the only follow-up worth keeping in mind is the per-plot Model: claude-opus-4-8 |
c3c232d to
779de35
Compare
779de35 to
8f05114
Compare
Pinned plot data is fetched lazily behind an IntersectionObserver. Its initial notification is not reliably delivered for elements that are already in view at mount, and it can also miss a plot that a layout shift moves into view. As sibling plots stream in their data the surrounding skeletons change height, so a plot can move into the viewport without a scroll, and on an otherwise idle page that change is not always reported. Either way, an in-view plot could stay stuck on the loading skeleton until the user scrolled or refreshed. On mount, measure the element and mark it visible immediately when it is already on or near the screen. For plots that start below the fold, keep observing for scroll-into-view (with a preload margin) and also watch for layout changes with a ResizeObserver, so a shift that brings the plot into view without a scroll is picked up. Both observers are torn down by a single owner-scoped cleanup. Extract the viewport check into a pure isNearViewport helper with unit tests.
8f05114 to
8a32011
Compare
Problem
Pinned plots on a project's Plots page could take a long time to appear when navigating to the page, while a refresh made them show up right away. Occasionally a plot would also stay on its loading skeleton until the user scrolled or refreshed.
Root cause
Each pinned plot's data is fetched lazily, gated behind an
IntersectionObserverinPinnedFrame. The observer's initial notification is not reliably delivered for elements that are already in the viewport at mount time and never subsequently move. On top of that, the skeleton placeholder and the rendered chart have different heights, so as sibling plots stream in their data the layout shifts and a plot can move into view without a scroll. On an otherwise idle page that intersection change is not always reported, so an in-view plot could stay stuck on the skeleton until a scroll or refresh forced a new rendering pass.Fix
isNearViewporthelper with unit tests.Testing
isNearViewportand the settling constants (npx vitest run).biome formatandbiome lintclean.