Repository navigation
test(content): wait for the dialog's first focus before opening the JSON-LD code - #1753
Merged
Merged
Conversation
…SON-LD code The Before you publish test "opens and folds the code with one button" clicked Show the JSON-LD straight after the dialog rendered. Base UI's focus manager moves the dialog's initial focus (initialFocus = Continue to send) with requestAnimationFrame, which jsdom runs on a ~16.7 ms setInterval. Async act() hands over to setImmediate after flushing, so a timer that came due meanwhile runs there. When the run was slow (memory pressure, swap) and more than one frame passed between the dialog opening and the code's focus effect, that deferred initial focus landed after the effect and took the focus back to the button: "expected <button> to be <pre>". Fast runs passed, so it failed or passed by machine load, not by date (the file passes with Date faked across several dates and times). Not a product bug: in a browser the initial focus lands a frame after the dialog opens, before anyone can click Show. The test now waits for that focus, as the Export test in the same file does, and still expects the focus on the code it opens. Reproduced with a 20 ms busy wait in the click (3/3 failed before, 3/3 passed after). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 29, 2026
Merged
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good
Reviewed 724f0d1, branched from ce9a3dc. One test file, no product code.
What I checked
- The race is as described. I put a 25 ms busy wait right before the click on "Show the JSON-LD". Without this line, the test fails with
expected <button> to be <pre>, the same error seen on main. With it, the test passes. The wait is the one the Export test in the same file already uses. - The assertion that matters is unchanged: focus lands on the code it opens.
- The file passes (37/37) on this branch merged with main. Prettier is clean.
- It merges cleanly on current main.
5 of 6 tasks
6 tasks done
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
_before-publish.test.tsx› "opens and folds the code with one button, its focus on the code it opens" failed on main whenever the machine was slow. It went red on three branches that don't touch the editor, and once even run alone.Root cause: a race in the test, not a product bug.
requestAnimationFrame, about 16.7 ms under jsdom).<pre>.expected <button> to be <pre>.The fix is one line in the test: wait for the dialog's first focus before clicking, as the Export test in the same file already does:
The assertion that matters (focus lands on the opened code) is unchanged, and the component is untouched. In a browser nobody can click "Show" within the frame before the first focus settles.
How it was checked
Dateat six dates and times (37/37 each), which rules out a dependency on today's date.Related issue
None (flaky test on main).
Type of change
test— Tests onlyHow to test
cd web && yarn vitest run 'src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_before-publish.test.tsx': 37/37 pass, also while the machine is busy.Checklist
🤖 Generated with Claude Code