-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Editor: Fix block color contrast checker #68799
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +95 B (+0.01%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for working on this, George!
Everything is testing great on my end, and the code looks solid.
Screen.Recording.2025-01-21.at.10.57.18.mov
// Combine `useLayoutEffect` and two rAF calls to ensure that values are read | ||
// after the current paint but before the next paint. | ||
window.requestAnimationFrame( () => | ||
window.requestAnimationFrame( updateColors ) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix. The rest is just moving code around for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that the actual fix is removing the [ blockEl ]
dependency array from the effect. Then it runs on every render, not only on blockEl
change (the block's DOM element hardly ever changes), and catches all the color updates.
Running after the current paint but before the next paint is exactly what useEffect
does. It runs when the rendered DOM is already painted. You shouldn't need to simulate it with layout effect + rAF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsnajdr, the component had an issue before adding blockEl
as a dependency. It didn't always work, and the computed properties from blockEl
were stale.
You shouldn't need to simulate it with layout effect + rAF.
I would like to avoid it as well, but this the only solution that works.
Quoting from: #59227.
React does not guarantee that useEffect will be called after the browser paints and, in fact, useEffect can be called before a paint when React is handling a user event (e.g. a click) or if a useLayoutEffect in the component tree updates state (e.g. calls setState). See facebook/react#20863 (comment).
This is probably a better summary for React 18 - facebook/react#24409 (comment).
What?
Fixes #67035.
Alternative to #67036.
Combine
useLayoutEffect
and two rAF calls to ensure that values are read after the current paint but before the next paint.Why?
The solution is similar to #59227, which also needs to read computed styles from the block element.
Testing Instructions
Testing Instructions for Keyboard
Same.