Core Abilities: Export initialization promise as ready#77254
Core Abilities: Export initialization promise as ready#77254westonruter merged 2 commits intotrunkfrom
ready#77254Conversation
Consumers of `@wordpress/core-abilities` had no way to know when the server-side categories and abilities had finished loading into the client store, since `initialize()` was called fire-and-forget. Export the returned promise as `ready` so callers can `await` it before calling `getAbilities()` or `executeAbility()`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a usage example showing how to `await` the exported `ready` promise before calling `getAbilities()` or `executeAbility()`, since initialization is asynchronous (categories and abilities are fetched from the REST API on import). Related to #77253. Related to #76349. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +15 B (0%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 37ae845. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24307676022
|
jorgefilipecosta
left a comment
There was a problem hiding this comment.
Thank you for finding this issue and proposing a solution, this solution looks good to me 👍
* Core Abilities: Export initialization promise as `ready` Consumers of `@wordpress/core-abilities` had no way to know when the server-side categories and abilities had finished loading into the client store, since `initialize()` was called fire-and-forget. Export the returned promise as `ready` so callers can `await` it before calling `getAbilities()` or `executeAbility()`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Core Abilities: Document `ready` promise in README Add a usage example showing how to `await` the exported `ready` promise before calling `getAbilities()` or `executeAbility()`, since initialization is asynchronous (categories and abilities are fetched from the REST API on import). Related to #77253. Related to #76349. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: aa9c7e4 |
`@wordpress/abilities`' `executeAbility` looks up abilities in a client-side store. PHP-registered abilities only land there once `@wordpress/core-abilities` has fetched `/wp-abilities/v1/abilities` and registered each one. Without awaiting that initialization, the agent's first `execute_ability(...)` call failed with "Ability not found" and the model retried. Import `@wordpress/core-abilities` once at module load and await its exported `ready` promise (added in WordPress/gutenberg#77254) before delegating to `executeAbility`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
What?
Closes #77253
Why?
REST API calls to fetch the Abilities API endpoints must currently finish before modules may interact with
getAbilities()orexecuteAbility().How?
This exports the
Promisereturn value from theinitializefunction asreadyso that modules can await on that to resolve before attempting to access abilities.Testing Instructions
Add a plugin that does the following:
You should see a list of the abilities successfully logged along with the site info.
Use of AI Tools
Claude Sonnet 4.6 was used to propose a solution and implement the fix.