Skip to content

Migrate interactive directives off data-wp-on-async - #3220

Merged
pfefferle merged 15 commits into
trunkfrom
fix/data-wp-on-async-deprecation
May 12, 2026
Merged

pfefferle merged 15 commits into
trunkfrom
fix/data-wp-on-async-deprecation

Conversation

@pfefferle

Copy link
Copy Markdown
Member

Fixes https://wordpress.org/support/topic/data-wp-on-async-getting-deprecated-with-wp7-0/

Proposed changes:

WordPress 7.0 deprecates the data-wp-on-async--{event} directive and will remove it in a later release. A user flagged this on the support forum after seeing the console warning:

The usage of data-wp-on-async is deprecated and will stop working in WordPress 7.0. Please, use data-wp-on with the withSyncEvent() helper from now on.

Switch every occurrence to the new data-wp-on--{event} directive and wrap the underlying action handlers with withSyncEvent() so the Interactivity API keeps the event object synchronously available for callbacks that call preventDefault() or read event.key / event.target.

Source changes

  • src/follow-me/view.js — wrap onKeydown; render.php renames data-wp-on-async--keydowndata-wp-on--keydown.
  • src/remote-reply/view.js — wrap onReplyLinkKeydown; render.php renames both the click and keydown directives on the reply link.
  • src/shared/actor-list/store.js — wrap previousPage and nextPage. Used by the Followers and Following blocks' pagination (directives live in includes/class-blocks.php, also renamed).
  • src/shared/modal/index.js — wrap toggleModal and drop the legacy async selector from the close-button fallback lookups (no element ships with data-wp-on-async--click="actions.toggleModal" any more).
  • Build artefacts regenerated.

Other information:

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

No new tests. Behaviour is unchanged — only the directive name and the handler annotation. The existing interactive E2E coverage exercises the changed paths (follow-me modal open/close, remote-reply link, followers/following pagination, reactions modal).

Testing instructions:

  1. Load a site with the ActivityPub plugin on WordPress 7.0 (or current trunk with the deprecation warning active). Open the browser console.
  2. Visit a page with the Follow Me, Remote Reply, Followers/Following, or Reactions block. Before this PR, the console logs The usage of data-wp-on-async is deprecated…. After this PR, no such warning appears.
  3. Click the Follow button → modal opens.
  4. Tab to the Follow button, press Enter / Space → modal opens (keyboard path).
  5. Click the Reply link on a comment → modal opens. Keyboard Enter also opens it.
  6. On a Followers / Following pagination, click Next / Previous → page changes.
  7. On a reactions-enabled post, click the reactions modal trigger → opens / closes.

Changelog entry

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

Significance

  • Patch

Type

  • Fixed

Message

Silence the upcoming WordPress 7.0 deprecation warning about data-wp-on-async by switching the plugin's interactive blocks to the new withSyncEvent() helper.

WordPress 7.0 deprecates the `data-wp-on-async--{event}` directive
and will remove it in a later release. Reported by @kimusan on the
plugin's support forum.

Switch every occurrence to the new `data-wp-on--{event}` directive and
wrap the underlying action handlers with `withSyncEvent()` so the
Interactivity API keeps the event object synchronously available for
the callbacks that call `preventDefault()` or read `event.key` /
`event.target`.

Source changes:
- src/follow-me: onKeydown handler wrapped; directive renamed in
  render.php.
- src/remote-reply: onReplyLinkKeydown wrapped; click + keydown
  directives renamed in render.php.
- src/shared/actor-list: previousPage / nextPage wrapped (used by the
  Followers and Following blocks' pagination).
- src/shared/modal: toggleModal wrapped; the legacy async selector is
  dropped from the close-button fallback lookups.
- includes/class-blocks.php: pagination directives renamed.

Build artefacts regenerated.
Copilot AI review requested due to automatic review settings April 24, 2026 10:51
@pfefferle pfefferle self-assigned this Apr 24, 2026
@pfefferle
pfefferle requested a review from a team April 24, 2026 10:51
@github-actions github-actions Bot added [Block] Follow Me [Block] Remote Reply aka "Reply on the Fediverse", in the comment list [Focus] Editor Changes to the ActivityPub experience in the block editor labels Apr 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

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 migrates interactive block directives off the deprecated data-wp-on-async--{event} syntax ahead of WordPress 7.0, switching to data-wp-on--{event} and wrapping affected handlers with withSyncEvent() to preserve synchronous event behavior.

Changes:

  • Replaced data-wp-on-async--{event} directives with data-wp-on--{event} in block render templates (Follow Me, Remote Reply, Followers/Following pagination).
  • Wrapped event-sensitive action handlers with withSyncEvent() in the relevant Interactivity stores/views.
  • Updated modal trigger lookup selectors to remove the legacy data-wp-on-async--click fallback and regenerated build artifacts.

Reviewed changes

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

Show a summary per file
File Description
src/shared/modal/index.js Wrapes toggleModal with withSyncEvent() and removes legacy async directive selectors for modal trigger lookups.
src/shared/actor-list/store.js Wraps pagination actions (previousPage / nextPage) with withSyncEvent().
src/remote-reply/view.js Wraps reply-link keydown handler with withSyncEvent().
src/remote-reply/render.php Updates reply link directives from data-wp-on-async--* to data-wp-on--*.
src/follow-me/view.js Wraps the follow button keydown handler with withSyncEvent().
src/follow-me/render.php Updates keydown directive from data-wp-on-async--keydown to data-wp-on--keydown.
includes/class-blocks.php Updates Followers/Following pagination directives to data-wp-on--click.
build/remote-reply/view.js Regenerated build output reflecting directive/handler updates.
build/remote-reply/view.asset.php Regenerated asset metadata/version hash.
build/remote-reply/render.php Regenerated render output with updated directives.
build/reactions/view.js Regenerated build output reflecting modal store changes (sync toggle + selector updates).
build/reactions/view.asset.php Regenerated asset metadata/version hash.
build/reactions/index.js Regenerated editor build output.
build/reactions/index.asset.php Regenerated asset metadata/version hash.
build/following/view.js Regenerated build output reflecting pagination handler wrapping.
build/following/view.asset.php Regenerated asset metadata/version hash.
build/following/index.js Regenerated editor build output.
build/following/index.asset.php Regenerated asset metadata/version hash.
build/followers/view.js Regenerated build output reflecting pagination handler wrapping.
build/followers/view.asset.php Regenerated asset metadata/version hash.
build/followers/index.js Regenerated editor build output.
build/followers/index.asset.php Regenerated asset metadata/version hash.
build/follow-me/view.js Regenerated build output reflecting keydown handler wrapping + modal store changes.
build/follow-me/view.asset.php Regenerated asset metadata/version hash.
build/follow-me/render.php Regenerated render output with updated directives.
build/follow-me/index.js Regenerated editor build output.
build/follow-me/index.asset.php Regenerated asset metadata/version hash.
.github/changelog/fix-data-wp-on-async-deprecation Adds a changelog entry for the deprecation-warning fix.

Comment thread src/shared/actor-list/store.js Outdated
Comment thread src/remote-reply/view.js Outdated
Comment thread src/follow-me/view.js Outdated
Comment thread src/shared/modal/index.js Outdated
…-deprecation

# Conflicts:
#	build/follow-me/index.asset.php
#	build/follow-me/index.js
#	build/followers/index.asset.php
#	build/followers/index.js
#	build/following/index.asset.php
#	build/following/index.js
#	build/reactions/index.asset.php
#	build/reactions/index.js
The plugin now imports withSyncEvent from @wordpress/interactivity, which
first shipped in WordPress 6.8. Older cores would fail to load the affected
block scripts.
@pfefferle

Copy link
Copy Markdown
Member Author

@jeherve any objections about raising the min WordPress version to 6.8?

@pfefferle
pfefferle requested a review from jeherve May 4, 2026 07:04
pfefferle added 3 commits May 5, 2026 11:22
`withSyncEvent` landed in WordPress 6.8 (Gutenberg 20.4). On WP 6.5–6.7
the symbol is undefined; calling it throws. The previous approach was
to bump the plugin's minimum WordPress version, which is a `major`
changelog significance and forces an upgrade on existing sites running
6.5–6.7 just to silence a 7.0 deprecation warning.

Add `src/shared/with-sync-event.js`: a 1-line shim that imports the
namespace from `@wordpress/interactivity` and falls back to the
identity function when `withSyncEvent` is undefined. Pre-6.8 actions
were synchronous by default, so the identity fallback is functionally
equivalent.

Update the four consumers (follow-me/view, remote-reply/view,
shared/actor-list/store, shared/modal) to import from the shim, revert
the `readme.txt` `Requires at least` back to 6.5, drop the
`bump-min-wp-version` changelog entry, and rebuild the affected view
bundles.
@pfefferle

Copy link
Copy Markdown
Member Author

Scratch the min-version question — landed a withSyncEvent compat shim in 974d3bf instead. Pre-6.8 the symbol is undefined and the shim falls back to identity; pre-6.8 actions were synchronous by default so the wrapping was a no-op there anyway. Min WP stays at 6.5, no major bump.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 29 changed files in this pull request and generated 1 comment.

Files not reviewed (9)
  • build/follow-me/index.js: Language not supported
  • build/follow-me/view.js: Language not supported
  • build/followers/index.js: Language not supported
  • build/followers/view.js: Language not supported
  • build/following/index.js: Language not supported
  • build/following/view.js: Language not supported
  • build/reactions/index.js: Language not supported
  • build/reactions/view.js: Language not supported
  • build/remote-reply/view.js: Language not supported

Comment thread src/shared/with-sync-event.js Outdated
pfefferle added 2 commits May 12, 2026 10:32
Copilot flagged that the previous shim — `import * as iAPI from
'@wordpress/interactivity'; iAPI.withSyncEvent ?? identity` — got
tree-shaken into a *named* import in the bundle:

    import { withSyncEvent as r } from "@wordpress/interactivity";

Native ESM enforces that named imports must exist, so on WP 6.5–6.7
the missing export would have thrown at module instantiation, before
the `??` fallback could run. The shim was protecting against an
`undefined` lookup, not against the actual failure mode.

Read the property via a `const`-aliased bracket access. The compiled
output now keeps the namespace import:

    import * as t from "@wordpress/interactivity";
    const o = t.withSyncEvent ?? (t => t);

Verified across all five view bundles. Namespace imports always
succeed; the property access yields undefined on older cores and the
identity fallback fires — behaviorally equivalent to the pre-6.8
sync-by-default actions.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 29 changed files in this pull request and generated no new comments.

Files not reviewed (9)
  • build/follow-me/index.js: Language not supported
  • build/follow-me/view.js: Language not supported
  • build/followers/index.js: Language not supported
  • build/followers/view.js: Language not supported
  • build/following/index.js: Language not supported
  • build/following/view.js: Language not supported
  • build/reactions/index.js: Language not supported
  • build/reactions/view.js: Language not supported
  • build/remote-reply/view.js: Language not supported

@jeherve jeherve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks and tests well. 🚢

@pfefferle
pfefferle merged commit aa563ef into trunk May 12, 2026
11 checks passed
@pfefferle
pfefferle deleted the fix/data-wp-on-async-deprecation branch May 12, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Follow Me [Block] Remote Reply aka "Reply on the Fediverse", in the comment list [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