fix: place the Tooltip before the browser paints it - #33
Merged
Merged
Conversation
Placement was measured in a frame scheduled after mount. Until that frame ran, the content was in the DOM carrying `visibility: hidden`: painted nowhere, out of the accessibility tree, and unfindable by any query that respects the tree. A layout effect measures it instead. The content is in the DOM by then, and the state it sets is flushed before paint, so the tooltip is never painted or exposed unplaced. This surfaced as a flaky consumer test: focus a glossary term, look for the tooltip, and lose the race with the frame on a loaded machine. The package's own tests could not see it, because every one of them stubbed `requestAnimationFrame` to run synchronously. Those stubs are gone, and one test now asserts the tooltip is in the tree in the same tick it opens, which is the assertion the stubs were papering over: putting the frame back fails ten tests.
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.
Placement was measured in a frame scheduled after mount. Until that frame ran, the content sat in the DOM carrying
visibility: hidden, which paints nowhere and, more to the point, takes it out of the accessibility tree: present, unreadable, and unfindable by any query that respects that tree.It measures in a layout effect now. The content is in the DOM by the time that runs, and the state it sets is flushed before the browser paints, so the tooltip is never painted or exposed unplaced. The scroll and resize re-measurement moved into the same effect.
How it surfaced
A continuum-hub test that focuses a glossary term and looks for its tooltip failed once in a full-suite run and passed on its own and in the next full run. It was racing the frame:
findByRolepolls the accessibility tree, the tooltip is not in it until placement lands, and a loaded worker can miss a 1000ms window waiting for a frame that a starved jsdom is slow to schedule.The package's own tests could not have caught this. Every one of them stubbed
requestAnimationFrameto run synchronously, which is exactly the frame under suspicion. That was reasonable when I wrote them, since the alternative was making every assertion wait on frame timing, but it meant the suite was blind to the thing the stub replaced.Tests
The stubs are gone, and all 31 tests run against real timing. One new test asserts the tooltip is in the accessibility tree in the same tick it opens, which is the assertion the stubs were standing in for.
Putting the frame back fails ten of them, including the new one.
pnpm run verifypasses.Refs lablup/continuum-hub#999