-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix: Make fit text work, when navigating with the interactivity api. #72797
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
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: +277 B (+0.01%) Total Size: 2.45 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 5de0cdd. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18920158142
|
|
I'm not happy with this solution, because I don't like having a mutation observer on frontend. If we could get a interactivity api based solution that does not needs mutation observer I would prever. |
5de0cdd to
4926db1
Compare
|
I will soon have a PR with a better alternative so there is no need for this one to be reviewed. |
This PR fixes an issue where fit-text is not working when navigating using the Interactivity API and in any case where fit-text blocks may be added dynamically with JavaScript. Props to @luisherranz for reporting this.
Solution
Instead of running once and assuming all fit-text blocks are static, we add a mutation observer. It just listens to node additions and removals after the load and checks if the node has or contains fit-text blocks. If it does and the node is removed, it cleans up the fit-text observer; if the node was added and has fit-text, it performs its initialization.
Other alternatives:
Overwrite the
push/popmethods of the navigation so we could catch and try to get anonNavigateevent and then do the fit-text init. This is not very reliable, as when the navigation happens, requests to the server may still be in progress and the DOM may not be ready.Try to use the Interactivity API directly. I guess we would need to add some invisible element which uses the Interactivity API as a way to try to subscribe to the navigation events on the Interactivity API. I tried that locally but my solution was going in a very hacky way.
cc: @luisherranz for thoughts on the current solution and in case you know a simpler alternative.
Testing Instructions