Fix live toast stale callback race#271
Open
jjoanna2-debug wants to merge 1 commit into
Open
Conversation
7ea74cf to
cff04ae
Compare
cff04ae to
31a5a56
Compare
Contributor
|
I am not able to repro this bug, can you share a minimal repo for us to test and repro it. |
Author
|
Sure. I added a minimal dependency-free repro repo here: https://github.com/jjoanna2-debug/impeccable-toast-race-repro Steps: git clone https://github.com/jjoanna2-debug/impeccable-toast-race-repro.git
cd impeccable-toast-race-repro
python3 -m http.server 4173Then open What it does:
The same page has Run fixed implementation, which uses the I kept it static and framework-free so the repro isolates the toast lifecycle race itself rather than depending on a particular React/Vite page shape. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dismissToast()or a newer toast from leaving stale callbacks that touchtoastElWhy
Fixes #268.
showToast()schedules an enterrequestAnimationFrame, butdismissToast()can remove the current toast and settoastEl = nullbefore that frame runs. The old callback then readtoastEl.styleand could throw. A plain null guard would close that crash, but it still leaves older timeout callbacks able to animate or remove a newer toast.This patch captures the created element as
currentToastand makes each delayed callback no-op unlesstoastEl === currentToast.Verification
node --test tests/live-browser-regression.test.mjsnode --test tests/live-browser-regression.test.mjs tests/live-browser-source.test.mjs tests/live-browser-dom.test.mjs tests/live-browser-script-parts.test.mjs tests/live-browser-session.test.mjsgit diff --checknpx --yes bun run test:livestill fails ontests/live-copy-edit-agent.test.mjs(flags invalid JSX syntax in post-apply checks); confirmed the same failure on cleanorigin/main.npx --yes bun run test:live-e2eis blocked in this checkout because@anthropic-ai/sdkis not installed.Note
Low Risk
Scoped UI toast lifecycle fix with regression tests; no auth, data, or API surface changes.
Overview
Fixes a timing race in live-mode
showToast()where enterrequestAnimationFrameand auto-dismisssetTimeoutcallbacks could run afterdismissToast()or a newer toast replaced the globaltoastEl, causing crashes or animating/removing the wrong toast.Each toast now binds delayed work to a local
currentToast; enter, fade-out, and removal callbacks no-op unlesstoastEl === currentToast. Regression tests inlive-browser-regression.test.mjslock in that ownership behavior.Reviewed by Cursor Bugbot for commit 31a5a56. Bugbot is set up for automated code reviews on this repo. Configure here.