Skip to content

Commit 68591aa

Browse files
Block editor: Make fit text work with the interactivity API.
Fit text did not work after navigating to a page using the Interactivity API router. When users navigated to a post via client-side navigation (e.g., in a Query block with pagination), fit text blocks would not recalculate their font sizes, appearing either too large or too small. This occurred because the fit text initialization only ran on the window.load event, which doesn't fire during client-side navigation. We refactored fit text front end to be an interactivity api first implementation, using an interactivity api init event instead of a window load event. This commit adds the required PHP changes. Props jorgefilipecosta, mukesh27, luisherranz. Fixes #64210. Built from https://develop.svn.wordpress.org/trunk@61145 git-svn-id: http://core.svn.wordpress.org/trunk@60481 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent afcbc33 commit 68591aa

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

wp-includes/block-supports/typography.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ function wp_typography_get_preset_inline_style_value( $style_value, $css_propert
308308
function wp_render_typography_support( $block_content, $block ) {
309309
if ( ! empty( $block['attrs']['fitText'] ) && ! is_admin() ) {
310310
wp_enqueue_script_module( '@wordpress/block-editor/utils/fit-text-frontend' );
311+
312+
// Add Interactivity API directives for fit text to work with client-side navigation.
313+
if ( ! empty( $block_content ) ) {
314+
$processor = new WP_HTML_Tag_Processor( $block_content );
315+
if ( $processor->next_tag() ) {
316+
if ( ! $processor->get_attribute( 'data-wp-interactive' ) ) {
317+
$processor->set_attribute( 'data-wp-interactive', true );
318+
}
319+
$processor->set_attribute( 'data-wp-context---core-fit-text', 'core/fit-text::{"fontSize":""}' );
320+
$processor->set_attribute( 'data-wp-init---core-fit-text', 'core/fit-text::callbacks.init' );
321+
$processor->set_attribute( 'data-wp-style--font-size', 'core/fit-text::context.fontSize' );
322+
$block_content = $processor->get_updated_html();
323+
}
324+
}
311325
}
312326
if ( ! isset( $block['attrs']['style']['typography']['fontSize'] ) ) {
313327
return $block_content;

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.9-beta3-61144';
19+
$wp_version = '6.9-beta3-61145';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)