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

Query Filter: Update to match new Interactivity API format #563

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Jan 26, 2024

There have been multiple changes to the Interactivity API since it was first used in the Query Filter blocks.

  • The view scripts must be modules now (see Tools: Update packages, use wp-scripts for build process #562), and are registered to WordPress with a new viewModule property in block.json (this will probably change to viewScriptModule soon, but both will continue to work).
  • The method for registering context & namespaces has changed, which means the hierarchy of data registered in the store() call is different, and the paths to data are updated— ex, effects.wporg.queryFilter.init is now effects.init.
  • Functions in the store don't get the store/context/ref, so these needed to be refactored to have access to the getContext function.
  • data-wp-effect is now data-wp-watch

See WordPress/gutenberg#52906 (comment), WordPress/gutenberg#57492.

Important

This requires a solution that lets us update Gutenberg to 17.5+ (for the viewModule registration), without breaking the Support Forums— like #561

To test

  1. Update node, deps, and build the project (see Tools: Update packages, use wp-scripts for build process #562 for instructions)
  2. Test with Showcase or Events, make sure the version of Gutenberg is up to date (see also Site Screenshot block: Update to support latest Interactivity API wporg-showcase-2022#268)
  3. Try using the filters- select items and applying should work
  4. Keyboard nav should work- open a filter with space or enter, tab through, select some items, apply or use escape to close the dropdown

@ryelle ryelle self-assigned this Jan 26, 2024
@ryelle ryelle force-pushed the update/query-filter-interactivity-api branch from 7e16206 to f40f856 Compare January 26, 2024 17:31
@ryelle ryelle force-pushed the update/tools-packages-build branch from 51b8e39 to 9ca0663 Compare January 26, 2024 18:20
@ryelle ryelle force-pushed the update/query-filter-interactivity-api branch from f7d72eb to 5f5c3a8 Compare January 26, 2024 18:21
@@ -1,8 +1,7 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The module build is not compatible with importing from other @wordpress/* packages, trying was giving me this error:

Module not found: Error: Attempted to use WordPress script in a module: @wordpress/i18n, which is not supported yet.

The workaround is to pass the label as a data attribute on the element from render.php. I don't think we'll need to do this forever, as this is currently being iterated on.

@ryelle ryelle marked this pull request as ready for review January 26, 2024 21:22
Copy link
Contributor

@adamwoodnz adamwoodnz left a comment

Choose a reason for hiding this comment

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

Got this working after some considerable config!

I needed to use WordPress/wporg-showcase-2022#268 and Gutenberg 17.5.2 (latest).

Filters work for me, I didn't test the screenshots specifically, but the errors went away after I updated Node and rebuilt everything.

The Interactivity API changes look ok to me but I'm still not familiar with the API at this stage.

Haven't tested with Events.

Base automatically changed from update/tools-packages-build to trunk January 29, 2024 21:36
This is a workaround for i18n functions, since they can't be imported into a module
@ryelle ryelle force-pushed the update/query-filter-interactivity-api branch from 8a45a04 to d77ef00 Compare January 29, 2024 21:38
Copy link
Member

@iandunn iandunn left a comment

Choose a reason for hiding this comment

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

I tested the built files with Gutenberg 17.5.3 on my events.wordpress.org sandbox (w.org, not local). Everything looks good 👍🏻

@ryelle ryelle merged commit fb48365 into trunk Feb 1, 2024
2 checks passed
@ryelle ryelle deleted the update/query-filter-interactivity-api branch February 1, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants