Skip to content

Reactions: Use Interactivity API #1722

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

Merged
merged 58 commits into from
May 26, 2025
Merged

Conversation

obenland
Copy link
Member

@obenland obenland commented May 20, 2025

Moves the Follow Me block to using the Interactivity API for front-end rendering. Removes the block's dependency on React in the frontend.

Proposed changes:

  • Replaces React frontend of Reactions block with Interactivity API.
  • Shows actual Reactions in the Editor when there are any available.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to the Editor and add a Reactions block.
  • Test it in the Editor and frontend and make sure it still works as expected.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

The Reactions block now uses the latest Block Editor technology for display on the frontend.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Moves the Reactions block to use the Interactivity API for front-end rendering and removes its React dependency.

  • Registers a new Interactivity store with actions and callbacks, binding state via data attributes in render.php.
  • Removes React-based view logic (src/reactions/view.js) and updates block metadata (block.json) to apiVersion 3 with interactivity support.
  • Refactors styles, save/render flows, and tests to align with the Interactivity API approach.

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/includes/class-test-blocks.php Updated tests to use assertStringContainsString and removed deprecated React-based test
src/reactions/view.js Replaced React rendering logic with Interactivity API store, actions, and callbacks
src/reactions/style.scss Added new SCSS for interactivity-based layout, avatar groups, and modal styles
src/reactions/save.js Adjusted save output to use useBlockProps.save wrapper and removed placeholder div
src/reactions/render.php Added server-side wp_interactivity_state, data-binding attributes, and interactivity init
src/reactions/edit.js Cleaned up dummy data generator signature and imported styles
src/reactions/block.json Bumped apiVersion to 3, added interactivity support, and updated view script entries
includes/class-blocks.php Removed explicit render_callback in register_block_type_from_metadata
.prettierignore Removed ignore for src/reactions so code is formatted by Prettier
Comments suppressed due to low confidence (1)

tests/includes/class-test-blocks.php:215

  • The tests now only check for partial HTML fragments and may miss missing or incorrect wrapper attributes. Consider adding assertions to verify the full markup, including data-wp-interactive bindings and block wrapper attributes to ensure complete coverage.
$this->assertStringContainsString( $expected, $output );

@obenland obenland requested a review from Copilot May 21, 2025 21:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Reactions block to use the new Interactivity API for front‑end rendering, removing the dependency on React while modernizing block registration and style definitions. Key changes include replacing React‑based frontend logic in view.js with interactivity‑based callbacks and actions, updating CSS styles and block.json metadata to reflect API Version 3, and adjusting PHP render logic to work with the new state management.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/reactions/view.js Replaced React rendering with Interactivity API actions and callbacks.
src/reactions/style.scss Updated styles and spacing, including modifications to gaps and layout.
src/reactions/save.js Modified wrapper structure for saved markup.
src/reactions/render.php Updated server‑side rendering to work with the new front‑end technique.
src/reactions/reactions.js Revised component props and parameters to remove unused values.
Other files Updated metadata, deprecation settings, and build configuration.

@obenland
Copy link
Member Author

@pfefferle This will likely need some more detail work on the Edit side, but should be good to test and get feedback on! Curious what you think of it!

@pfefferle
Copy link
Member

I've not looked too deep into the code yet, but it works quite well on my dev system.

}, [ buttonRef, items.length ] );

const visibleItems = items.slice( 0, visibleCount );
const visibleItems = items.slice( 0, 20 );
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the be visibleCount be configurable somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it needs to be. It was never really configurable, the above code would just adjust it to the amount of space it has available in the viewport. That is still the case on the frontend but won't be the case in the Editor, which this code is limited to now.

On the frontend, avatars will be server-side rendered, so without a limit it would create a flash of overflowing avatars on posts with a lot of reactions. 20 is an arbitrary number but seemed to work reasonably well in testing.

@obenland obenland merged commit c0c8410 into trunk May 26, 2025
12 checks passed
@obenland obenland deleted the update/reactions-interactivity branch May 26, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Follow Me [Block] Reactions [Feature] Reactions [Focus] Editor Changes to the ActivityPub experience in the block editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants