-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix: Fit Text flash during the binary search on the initial enabling. #72788
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
Fix: Fit Text flash during the binary search on the initial enabling. #72788
Conversation
|
Size Change: +79 B (0%) Total Size: 2.37 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 647df44. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18910736324
|
tyxla
left a comment
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 looks like a very tender fix 😅 I wonder if we can have an accompanying test to ensure it works as expected.
|
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. |
Hi @tyxla yes it is not a "fix" I'm proud of, unfortunately I don't think we can have tests for this as it is for a "browser quirck". The flash happens for less than one second and does not happens consistently etc. I don't think a test can reliably notice the flash it is very short visual thing. What we have is end to end tests that test the high level fit text functionality, and they are passing on this PR. |
|
|
||
| // Store current element value for cleanup | ||
| const currentElement = blockElement; | ||
| const previousVisibility = currentElement.style.visibility; |
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.
I've tested this by changing the content (triggers effect below), changing the parent viewport by modifying the window or hiding/showing the sidebar (triggers resize observer) but in none of those cases was I able to trigger the issue reported on activating fit text (first load).
This prompted me to think giving a better starting point for the binary search could be useful — as the flash does not happen in scenarios where the browser has a starting height closer to the output. Took a look at this but didn't get too far. I also saw you mentioned this path as something you investigated (but the flash was still present).
Given the time-constraints to get this fixed for 6.9, I've just approved this fix. It's an implementation detail that can be improved if we find a better way.
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.
giving a better starting point for the binary search could be useful
If the heuristics that @jorgefilipecosta explored in his stashed code are good enough, these seem like two mitigations that complement each other.
…#72788) Co-authored-by: jorgefilipecosta <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: mcsf <[email protected]>
|
I just cherry-picked this PR to the wp/6.9 branch to get it included in the next release: 8d41f3c |
|
Thanks for making this work, @jorgefilipecosta! It's not an obvious solution, but it seems like a compromise we can make. |
| // can still occur although rare. | ||
| showTimeoutId = setTimeout( () => { | ||
| currentElement.style.visibility = previousVisibility; | ||
| }, 10 ); |
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.
I suppose you tested with 0 and it wasn't good enough? (Your comment only touches on the choice of setTimeout but not the timeout.)
This PR tries to fix an issue raised by @mcsf where, when 'Fit text' is enabled, a temporary flash of a very large font size may be noticeable.
I tried other solutions (which are still stashed):
Direct hide and show without requestAnimationFrame. This did not work; the flash was still there.
Getting a better initial estimate for the binary search based on the parent width. In some cases, we could still get a flash, and the advantage was not worth the complexity.
Cloning the element, positioning it in the current position with absolute positioning (so it does not take space in the container), hiding our element, doing the calculation, showing it, and removing the clone. This also did not work; the flash was still there. That was when I noticed we needed requestAnimationFrame calls / a wait, and in that case, this solution provides the same result without as much complexity.
Before:
Screen.Recording.2025-10-29.at.13.46.35.mov
After:
Screen.Recording.2025-10-29.at.13.47.56.mov
Testing Instructions
Create multiple paragraphs with different text sizes, and another one staying in the placeholder state (e.g., "aa" and "aaaaaaaaaaaaaaaaaa").
Try to disable and enable 'Fit text' on all the paragraphs and verify there is no flash of a large font size.
Type in the different paragraphs with 'Fit text' enabled, and verify things still work and there is no noticeable hide/show effect (this logic should only apply when 'Fit text' is enabled).