Skip to content
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

Interactivity Router: Update for latest GB changes. #7304

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Sep 6, 2024

Accounts for changes to the @wordpress/interactivity-router module in:

Static localized strings are passed via script module data passing instead of in Interactivity API store state.
Redundant HTML used for aria-live regions is removed. This functionality is not handled by the @wordpress/a11y script module added in #7405.

Trac ticket: https://core.trac.wordpress.org/ticket/60647

Testing

Testing this requires package updates from WordPress/gutenberg#65539. It anticipates the package being released and updated in Core.

(Copied from WordPress/gutenberg#65539)

This PR is difficult to test on its own because it requires the package to be updated as a Core dependency for proper testing. It does not affect Gutenberg behavior, only the package's behavior in Core. There are other ways of doing it but this works:

  • Get a checkout of Core from Interactivity Router: Update for latest GB changes. #7304. This is the build that will be running.
  • Run npm ci in the Core checkout to install packages.
  • Build the package from this PR (npm run build:packages in Gutenberg).
  • Replace the @wordpress/interactivity-router package in Core's node_modules (node_modules/@wordpress/interactivity-router) with the package directory in Gutenberg (remove the directory and copy the directory from Gutenberg packages/interactivity-router).
  • In Core, run the npm build script you use, in my case npm run dev.

Then test out that the interactivity router a11y functionality is working. A good way to test is the query block with "force page reload" option disabled. Specifically, the aria-live regions of the page should be updated (with localized text if in non-English locale) announcing "Page loaded."


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Sep 6, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@sirreal
Copy link
Member Author

sirreal commented Sep 20, 2024

This is building on #7405.

@sirreal
Copy link
Member Author

sirreal commented Sep 20, 2024

See WordPress/gutenberg#65539

sirreal added a commit to WordPress/gutenberg that referenced this pull request Sep 24, 2024
@sirreal sirreal force-pushed the interactivity-router/pass-i18n-with-script-module-data branch from 1eb8e67 to 007480f Compare September 24, 2024 10:08
@sirreal sirreal changed the title Interactivity Router: Pass translated strings via script module data Interactivity Router: Update for latest GB changes. Sep 24, 2024
@sirreal sirreal force-pushed the interactivity-router/pass-i18n-with-script-module-data branch from be35932 to 14cf936 Compare September 25, 2024 19:04
sirreal added a commit to WordPress/gutenberg that referenced this pull request Sep 25, 2024
sirreal added a commit to WordPress/gutenberg that referenced this pull request Sep 26, 2024
@sirreal sirreal force-pushed the interactivity-router/pass-i18n-with-script-module-data branch from 14cf936 to f2ba5de Compare September 26, 2024 09:49
@sirreal sirreal marked this pull request as ready for review September 26, 2024 09:52
Copy link

github-actions bot commented Sep 26, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, swissspidy, czapla.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

sirreal added a commit to WordPress/gutenberg that referenced this pull request Sep 26, 2024
Update the interactivity-router package to use the @wordpress/a11y module for its aria-live regions.

This was behind a Gutenberg-only flag. Since the a11y module is landing in Core in 6.7, the flag can be removed to always use the a11y module.

See WordPress/wordpress-develop#7304.
gutenbergplugin pushed a commit to WordPress/gutenberg that referenced this pull request Sep 26, 2024
Update the interactivity-router package to use the @wordpress/a11y module for its aria-live regions.

This was behind a Gutenberg-only flag. Since the a11y module is landing in Core in 6.7, the flag can be removed to always use the a11y module.

See WordPress/wordpress-develop#7304.
Copy link
Contributor

@michalczaplinski michalczaplinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @sirreal ! 👍

I've tested it following the instructions in the PR.

@@ -990,12 +1011,6 @@ class="wp-interactivity-router-loading-bar"
data-wp-class--start-animation="state.navigation.hasStarted"
data-wp-class--finish-animation="state.navigation.hasFinished"
></div>
<div
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to bring this up after having already approved!

I've just noticed that we should rename the function to print_router_loading_markup(), update its docstring and update the reference where we pass this function to the filter over here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public method, extenders could be calling it or modifying its behavior in filters. Renaming the method could be disruptive. It's true the method name isn't a perfect description now. What do you think of adding a note in the method documentation instead of changing the name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do this:

  • Create a new print_router_markup function
  • Deprecate the “old” method, and have it log a deprecation.
  • The “old” method calls the new print_router_markup function.

I think that might be the way to go.

I’m looking at some existing functions/methods that have the @deprecated docstring. For example this function is deprecated, calls _deprecated_function() and then calls the updated version:

/**
* Prints inline scripts registered for a specific handle.
*
* @since 4.5.0
* @deprecated 6.3.0 Use methods get_inline_script_tag() or get_inline_script_data() instead.
*
* @param string $handle Name of the script to print inline scripts for.
* Must be lowercase.
* @param string $position Optional. Whether to add the inline script
* before the handle or after. Default 'after'.
* @param bool $display Optional. Whether to print the script tag
* instead of just returning the script data. Default true.
* @return string|false Script data on success, false otherwise.
*/
public function print_inline_script( $handle, $position = 'after', $display = true ) {
_deprecated_function( __METHOD__, '6.3.0', 'WP_Scripts::get_inline_script_data() or WP_Scripts::get_inline_script_tag()' );
$output = $this->get_inline_script_data( $handle, $position );
if ( empty( $output ) ) {
return false;
}
if ( $display ) {
echo $this->get_inline_script_tag( $handle, $position );
}
return $output;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've searched for the method name and it only appears in Gutenberg across searchable plugins and themes.

Let's just rename it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right!

The print_router_loading_and_screen_reader_markup method name was very
specific about its behavior which has changed. Rename the method to a
more descriptive name and update its documentation.
Copy link
Contributor

@michalczaplinski michalczaplinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 👍

@michalczaplinski
Copy link
Contributor

@sirreal sirreal deleted the interactivity-router/pass-i18n-with-script-module-data branch September 26, 2024 18:29
@sirreal
Copy link
Member Author

sirreal commented Sep 27, 2024

This was reverted to avoid removing the public method.

New PR with these changes: #7447

peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Sep 29, 2024
Update the interactivity-router package to use the @wordpress/a11y module for its aria-live regions.

This was behind a Gutenberg-only flag. Since the a11y module is landing in Core in 6.7, the flag can be removed to always use the a11y module.

See WordPress/wordpress-develop#7304.

Source: WordPress/gutenberg@7d883a4
peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Sep 29, 2024
Update the interactivity-router package to use the @wordpress/a11y module for its aria-live regions.

This was behind a Gutenberg-only flag. Since the a11y module is landing in Core in 6.7, the flag can be removed to always use the a11y module.

See WordPress/wordpress-develop#7304.

Source: WordPress/gutenberg@20ae57d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants