Repository navigation
fix(toasts): load the star toast chunk before showing it so hover stays still - #51913
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
…ys still
StarNagToastHost rendered the lazy StarNagToast inside
<Suspense fallback={null}> within toast.custom. Sonner measures a custom
toast's height on its first render, so it recorded 0px and pinned the
hovered card to that height, making the toast jump and its buttons hard
to click.
Load the chunk with createSharedChunkLoad before calling toast.custom,
as stablyai#51229 did for the resume report. A hide, a newer show or an unmount
while the chunk is loading abandons the pending show. Move
shared-chunk-load next to lazy-with-retry now that two features use it.
Fixes stablyai#51912
Co-authored-by: Neil <[email protected]>
6e933db to
07b8420
Compare
ELI5
When you hovered the "Onboarding completed! / Star on GitHub" popup, it jumped up and down, so its buttons were hard to click. The popup was measured before its contents had loaded, so it was recorded as zero pixels tall and that wrong size was never corrected. Now the contents load first and the popup appears after, so it gets the right size and stays still when you hover.
What Changed
StarNagToastHostloads the lazyStarNagToastchunk withcreateSharedChunkLoadfirst, then callstoast.customwith the loaded component. It no longer renders the toast inside<Suspense fallback={null}>. If a hide, a newer show or an unmount arrives while the chunk is loading, the pending show is dropped, so two quick shows produce one toast.shared-chunk-load.tsand its test moved unchanged (100% rename) fromcomponents/native-chat-recovery/toast/toapp-shell/startup/, next tolazy-with-retry, because two features use it now. The import inNativeChatResumeToastHostis updated.Why
Sonner (2.0.7) measures a custom toast's height once, on its first render. #50945 made
StarNagToastlazy, so the first render was the null Suspense fallback and Sonner recorded--initial-height: 0px. On hover, Sonner pins the expanded card to that height, which made the card drop and flicker. #51229 fixed the same bug for the resume report by loading the chunk before issuing the toast. This PR reuses that loader. The chunk stays lazy, so the startup gain from #50945 is kept. A static import would also fix the bug but would give that gain back.Linked Issue
Fixes #51912
Visual Proof
Taken from a headless component fixture that renders the real
StarNagToastHost,StarNagToastand the appToaster, with a stubbedwindow.api.starNag, while the pointer hovers the toast. These are not screenshots of the packaged app.Before (main): the hovered card is pinned to a 0px height and drops below its anchor. Only the header row is visible.
After (this PR): the hovered card keeps its full height and stays in place.
--initial-heightlaterIPC callTesting
Reproduced in a headless Chromium component fixture with real-pointer hover, sampling the card's position every animation frame. On main the card shifted 144px and expand/collapse toggled on most frames. With the fix: 0px shift and one toggle. "Later" and the close button each send exactly one IPC call.
Race cases in the same fixture: two shows before the chunk loads give one toast (the newer one) and no dismiss IPC. A show followed by a hide before the chunk loads gives no toast and no IPC.
The existing
tests/component-fixtures/resume-toast-hover.spec.tspasses 6/6 after the move.vitestonshared-chunk-load.test.tsandlazy-with-retry.test.ts: 5/5 pass.On the touched files: oxlint, oxfmt, anti-slop oxlint, native code-quality oxlint, ast-grep and
check-changed-code-quality.mjsare all clean. Targeted typecheck is clean.Platforms: the contributor tested on Windows 11. The fixture was also run headless on macOS. This is renderer-only code with no platform-specific logic.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
No new automated test. The existing
shared-chunk-loadtest only moved with its module. The hover behavior was checked with a throwaway headless fixture (results above). Component-fixture specs don't run in CI, andresume-toast-hover.spec.tsalready covers the same load-before-issue pattern.Performance
None, because
star-nag:showfires at most once per prompt and only one host is mounted. The chunk is still fetched lazily, only when the toast is requested. The only change is that the toast waits for the fetch instead of rendering an empty shell first. Measured with the realcreateSharedChunkLoadpath: a show with the chunk cached takes p50 0.2us and p99 1.0us per request plus await. 200 rapid shows before the chunk resolves take 0.139 ms of sync work in total, call the factory once and issue one toast. At N=200 tabs, panes or worktrees there is still one handler call and one chunk request per show, the same as main. No store, selector or memo changes, no sync I/O, no polling and no new startup bytes (shared-chunk-loadwas already in the startup bundle). The per-frame relayout loop on hover is gone.Risk
The riskiest part is the short gap between main's
star-nag:showand the toast being issued. A hide, a newer show or an unmount in that gap cancels the pending toast, which is the intended behavior. On first show the toast appears after its local chunk loads (a few ms) instead of as an empty 0px shell.Known limitation, unchanged by this PR: main counts the prompt as shown when it sends the event. If the chunk fails to load, no toast appears (a warning is logged, and lazy-chunk reload recovery still applies while the request is waiting).
Renderer only. No changes to saved data, settings, IPC, SSH or mobile. A plain revert backs it out.
Level: Low
Review
Agent skill upstream boundary
Notes
Follow-up, out of scope:
src/renderer/src/components/plugins/dialogs/PluginUpdateReviewHost.tsxstill renders a lazyPluginUpdateReviewToastinside<Suspense fallback={null}>withintoast.custom, so it probably has the same 0px first-measure bug. It should get the same fix in a separate PR.Original fix by @gomezacero in #51913.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)