gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Interactivity API: Iteration for WP 6.6

Open DAreRodz opened this issue 2 years ago • 23 comments

  • Part of https://github.com/WordPress/gutenberg/issues/41236.

We completed everything for the first public release of the Interactivity API in WordPress 6.5. Now, during the next iteration―which is going to be shorter―, we aim to focus on improving the current API without releasing new features. This includes enhancing the developer experience (especially during debugging), better test coverage and code quality, as well as fixing any reported bugs.

Note that the list is expected to be modified. I've also added optional tasks we can work on if we find the time.

Tasks

  • Bug fixes
    • [x] https://github.com/WordPress/gutenberg/pull/60474
    • [x] https://github.com/WordPress/gutenberg/pull/60661
    • [x] https://github.com/WordPress/gutenberg/issues/60683
      • [x] https://github.com/WordPress/gutenberg/pull/61009
    • [ ] https://github.com/WordPress/wordpress-develop/pull/6405
    • [ ] https://github.com/WordPress/gutenberg/pull/60744
    • [x] https://github.com/WordPress/gutenberg/pull/61249
    • [ ] https://github.com/WordPress/gutenberg/pull/61409
  • Debugging
    • [ ] #60035
      • [ ] https://github.com/WordPress/wordpress-develop/pull/6413
    • [x] #59829
    • [x] #60049
    • [ ] Better error logging We need to locate which errors we need to inform about. Examples:
      • Throw an error when no namespace is specified when executing a directive.
      • directives incorrectly written

        This one is tricky. In the future, missing directives can be hydrated later on, or not have a callback associated, thus being undefined in the directives registry.

      • undefined props from the store

        Similar case as the previous one; missing attributes from the store can be added later on. We need to ensure that reading undefined attributes doesn’t raise any errors.

  • Code quality
    • [ ] Document data-wp-ignore directive
    • [ ] Move the whole runtime to TypeScript
      • https://github.com/WordPress/gutenberg/pull/58718
      • https://github.com/WordPress/gutenberg/pull/60149
      • https://github.com/WordPress/gutenberg/pull/59865
    • [ ] https://github.com/WordPress/gutenberg/issues/61371
    • [ ] https://github.com/WordPress/gutenberg/issues/61455
    • [ ] Add missing JSDoc comments
    • [ ] Optional: Unify state and context proxies with deepsignal
  • Testing
    • [ ] Increase test coverage, add edge cases.
    • [ ] Add unit tests (utils, toVdom, etc.)
  • Router
    • [ ] Optional: Load new scripts and style assets on client navigation
    • [ ] Optional: https://github.com/WordPress/gutenberg/issues/59856
    • [ ] Experiment: Full client-side navigation
      • #59707
  • Directives
    • [ ] Optional: Allow directives to be loaded asynchronously
      • https://github.com/WordPress/gutenberg/pull/60670
    • [ ] Optional: Add the data-wp-show directive
    • [ ] Allow static blocks in wp_kses function.
  • Performance
    • [ ] https://github.com/WordPress/gutenberg/issues/61634
    • [ ] Optional: https://github.com/WordPress/gutenberg/issues/58705
    • [ ] Experiment: https://github.com/WordPress/gutenberg/pull/58284
  • Enhancements
    • [x] https://github.com/WordPress/gutenberg/issues/59752 - https://github.com/WordPress/gutenberg/pull/60006/
    • [ ] https://github.com/WordPress/wordpress-develop/pull/6394
    • [ ] https://core.trac.wordpress.org/ticket/61039 - handle array or object access in PHP directive processing

DAreRodz avatar Mar 26 '24 17:03 DAreRodz

@DAreRodz @gziolo What's the best path to consider additional workstreams for the Interactivity API for 6.6?

Context is that @westonruter and myself have been exploring ideas to facilitate better INP performance centrally via the Interactivity API. For instance, we could automatically yield certain actions and callbacks to the main thread to reduce contention between multiple event listeners. We're close to formalizing our proposal in an issue, and it would be great to eventually include this effort here, if the team is on board.

One of the changes we're proposing may require a BC break in the API which we could handle with a deprecation strategy, but it would also benefit from being implemented sooner than later, now that the API is still very new and not yet as widely adopted outside of core.

felixarntz avatar Apr 02 '24 19:04 felixarntz

Hey @felixarntz, thanks for raising this up! 😊

I'm unsure what would be the "best path" (maybe @gziolo could help), but as this tracking issue is meant to be flexible, I would be happy to include your work. Let's wait for the proposal to see if we can have it ready for WP 6.6 and how the mentioned breaking changes could impact the current API.

DAreRodz avatar Apr 03 '24 09:04 DAreRodz

That sounds excellent, @felixarntz. I'm looking forward to seeing the proposal.

@DAreRodz, the Iteration issues mostly bring focus and increase the visibility of what to expect in WordPress 6.6, but it doesn't mean we can't change it. In practice, we should always be open to changing the plans based on the feedback and discoveries from the community experts 😍

gziolo avatar Apr 03 '24 09:04 gziolo

The ability to use existing WordPress Scripts from Script Modules is one of the most impactful things we can work on for the Interactivity API. Anything built with the Interactivity API must be a script module, so although it's not strictly Interactivity API, resolving this ticket for script and module interoperability seems very important: https://core.trac.wordpress.org/ticket/60647

sirreal avatar Apr 04 '24 11:04 sirreal

Second @sirreal calls for WordPress scripts. We use wp-api-fetch and wp-url with interactive blocks, a lot. Making that easier from a dev tooling perspective to automatically enqueue those scripts would be greatly appreciated.

sethrubenstein avatar Apr 04 '24 11:04 sethrubenstein

Is there any chance to get interactivity api outside of blocks? For example in custom php templates?

ermincelikovic avatar Apr 05 '24 12:04 ermincelikovic

@ermincelikovic While I believe it's not documented, it should already be possible. The main caveat is that by default custom PHP templates wouldn't be processed server-side, so you have to make sure the attributes that are dynamic via the Interactivity API are initialized with their correct value.

As a proof of concept, I have been working on https://github.com/WordPress/wordpress-develop/pull/5795 where I am using the Interactivity API for all dynamic functionality of the Twenty Twenty-One theme. Maybe that's helpful.

felixarntz avatar Apr 05 '24 17:04 felixarntz

default custom PHP templates wouldn't be processed server-side, so you have to make sure the attributes that are dynamic via the Interactivity API are initialized with their correct value

You can process them using wp_interactivity_process_directives 🙂

luisherranz avatar Apr 07 '24 15:04 luisherranz

default custom PHP templates wouldn't be processed server-side, so you have to make sure the attributes that are dynamic via the Interactivity API are initialized with their correct value

You can process them using wp_interactivity_process_directives 🙂

This looks great! How would I import { store, getContext } from "@wordpress/interactivity"; within a context of php template or a traditional script.js file in the theme though?

EDIT: Just found out that script modules are also introduced in 6.5: https://make.wordpress.org/core/2024/03/04/script-modules-in-6-5/

ermincelikovic avatar Apr 07 '24 19:04 ermincelikovic

I've added the suggestions in Typescripting utils PR. Ready to be reviewed again. https://github.com/WordPress/gutenberg/pull/60149/

cbravobernal avatar Apr 09 '24 14:04 cbravobernal

How would I import { store, getContext } from "@wordpress/interactivity"; within a context of php template or a traditional script.js file in the theme though?

@ermincelikovic The @wordpress/interactivity script module is only available to other script modules at this time. Using it from WordPress scripts is not supported at this time. See this ticket for details.

sirreal avatar Apr 10 '24 13:04 sirreal

I've added two PRs to the description above.

  • https://github.com/WordPress/gutenberg/pull/60661
  • https://github.com/WordPress/gutenberg/pull/60670

The first one could be considered a bug fix (I've added it under that category), and so be released in a minor WP release.

DAreRodz avatar Apr 11 '24 15:04 DAreRodz

The fix for data-wp-on is merged.

  • https://github.com/WordPress/gutenberg/pull/60661

I've also opened an issue to fix the same problem in data-wp-on-window and data-wp-on-document.

  • https://github.com/WordPress/gutenberg/issues/60683

DAreRodz avatar Apr 11 '24 19:04 DAreRodz

In addition to https://github.com/WordPress/gutenberg/issues/60035 I'd love to see some more useful debugging for the following areas:

  • output a warning when you use directives in the markup of a block that doesn't have the interactivity support enabled

  • add better client side errors when you try to access a property on a store that doesn't exist

  • add a guide for how to connect the preact dev tools to the interactivity API


Besides debugging here are some other things that I would love to see in the 6.6 cycle.

  • some documentation for working with external stores / making a store extensible

  • refine clarity in documentation of what the difference between callbacks and actions are

  • add documentation for client side routing like the query block does it

fabiankaegy avatar Apr 15 '24 15:04 fabiankaegy

I've added https://github.com/WordPress/wordpress-develop/pull/6394 for server-side derived state. It's ready for review.

sirreal avatar Apr 18 '24 11:04 sirreal

I've just added 3 items related to data-wp-ignore directive.

I think there's a bug with the server processing of ignore directives I'm attempting to fix in https://github.com/WordPress/wordpress-develop/pull/6405. I think that nodes with that attribute and their descendants should be ignored completely, no processing should happen on or under a node with data-wp-ignore. @cbravobernal or @DAreRodz can you confirm?

Right now ignore directives are not handled on the server, so those nodes and their descendants are processed. I discovered that while working on tests for #60744.

sirreal avatar Apr 18 '24 14:04 sirreal

I've created this ticket to handle property access on PHP objects in interactivity state, only arrays are well handled at the moment: https://core.trac.wordpress.org/ticket/61039

sirreal avatar Apr 18 '24 15:04 sirreal

I've created a PR to add a couple of warnings if Server Directives processing fails.

  • https://github.com/WordPress/wordpress-develop/pull/6413

cbravobernal avatar Apr 22 '24 15:04 cbravobernal

Created a PR to handle multiple document and window events in the same element.

  • https://github.com/WordPress/gutenberg/pull/61009

cbravobernal avatar Apr 23 '24 16:04 cbravobernal

Created a PR to avoid a wrong directive from killing the runtime.

  • https://github.com/WordPress/gutenberg/pull/61249

cbravobernal avatar May 06 '24 16:05 cbravobernal

Added another PR, avoiding an emtpy or a wrong namespace from killing the runtime too.

  • https://github.com/WordPress/gutenberg/pull/61409

cbravobernal avatar May 06 '24 18:05 cbravobernal

Added a follow-up issue to improve the readability of the directive processing function inside vdom.ts as @sirreal requested in https://github.com/WordPress/gutenberg/pull/61249#discussion_r1592540765

  • https://github.com/WordPress/gutenberg/issues/61455

cbravobernal avatar May 07 '24 18:05 cbravobernal

Added another performance issue which came out of the discussion in https://github.com/WordPress/gutenberg/discussions/60574#discussioncomment-9060900:

  • https://github.com/WordPress/gutenberg/issues/61634

westonruter avatar May 14 '24 00:05 westonruter

Added a minimum PR with two types:

  • https://github.com/WordPress/gutenberg/pull/61687

cbravobernal avatar May 15 '24 15:05 cbravobernal

Based on discussion in https://github.com/WordPress/gutenberg/discussions/60979#top I've opened a PR to add build configuration for a standalone package:

  • https://github.com/WordPress/gutenberg/pull/61681

michalczaplinski avatar May 16 '24 11:05 michalczaplinski

I've started a PR to migrate @wordpress/interactivity-router to TS:

  • https://github.com/WordPress/gutenberg/pull/61730/

michalczaplinski avatar May 16 '24 16:05 michalczaplinski

Hi all 👋

Reminder: The release candidate for Gutenberg Version 18.5 is scheduled for next Friday (May 31st). So anything that is supposed to make it into WordPress 6.6 must be merged by then.

Please raise any important issues that need additional attention :)

fabiankaegy avatar May 21 '24 14:05 fabiankaegy

Hi 👋

I updated the description of the main tracking issue with the list of PRs that won't be included in this release, the PRs that still needs review or commit and the PRs ready for 6.6.

cbravobernal avatar May 28 '24 17:05 cbravobernal

I've added https://github.com/WordPress/wordpress-develop/pull/6453 as an enhancement for 6.6 (let Interactivity API be used in WP Admin).

sirreal avatar May 29 '24 09:05 sirreal

I've added a unit test to the bug fix for the fatal error if a state or context uses a stdClass. Ready to review: 👀 https://github.com/WordPress/wordpress-develop/pull/6672

cbravobernal avatar May 29 '24 15:05 cbravobernal