Repository navigation
Search: decouple AI Answer block from jetpack_search_ai_answers_enabled (RSM-3608) - #48993
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
This comment has been minimized.
This comment has been minimized.
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Search plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot rebase the pr |
…ed (RSM-3608)
The block was previously gated by the site-wide
`jetpack_search_ai_answers_enabled` option (via `AI_Answers::is_enabled()`):
on `render.php` it bailed to an empty string, in the seeded Interactivity
state `aiAnswersEnabled` shadowed it, and `fetchAiAnswer` /
`showExtendedAiAnswer` / the `aiPanelHidden` getter all consulted the
flag. That coupled two unrelated decisions: whether the *overlay* AI
Answers fires (where the option is the right gate, because the overlay
is the default UX on any search page), and whether the *embedded block*
an author explicitly inserted into post content should render (where
block presence already *is* the opt-in signal).
This change makes the block stand on its own:
* `render.php`: drop the `AI_Answers::is_enabled()` early return. The
block renders whenever it's present in post content.
* `Search_Blocks::build_initial_state()`: drop the `aiAnswersEnabled`
seed key — no block-side consumer reads it.
* `store/index.js`:
* Remove the `aiAnswersEnabled` guards in `actions.fetchAiAnswer()`
and `actions.showExtendedAiAnswer()`. The fetch is already gated
by `aiBlockPresent` (set when the block mounts) plus the standard
query-length + same-query memo.
* Remove the `aiAnswersEnabled` clause from `aiPanelHidden`. Visible
status alone determines whether the panel reserves space.
* Tests: drop the `update_option / delete_option` setup and the
`test_disabled_renders_nothing` PHP case; add a single test that
asserts the block renders with the option off, unset, and on.
Drop the matching JS tests; the rest stop setting
`state.aiAnswersEnabled` since it no longer exists.
Overlay behaviour is unchanged — `class-helper.php` still localizes
`aiAnswersEnabled` for the overlay surface, and the overlay's
`search-app.jsx` still consults it.
…comment (RSM-3608) The comment listed the gates fetchAiAnswer() consults — but the 'enable-flag' (aiAnswersEnabled) check was removed in the parent commit. Update the list to just 'query length (≥ 3 chars) + same-query memo'.
9e2907d to
34d5036
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Code Coverage SummaryCoverage changed in 3 files.
|
🤖 Review-cycle summary —
|
| Source | Item | Resolution |
|---|---|---|
claude[bot] |
Stale "enable-flag" reference in store/index.js:987 call-site comment for actions.fetchAiAnswer() (the aiAnswersEnabled check was removed by this PR but the comment still listed it as a gate) |
Updated to "query length (≥ 3 chars) + same-query memo" in 34d5036502 |
Mid-loop rebase: parent PR #48986 merged at 05:19. This PR (originally based on raven/rsm-3591-ai-answer-block) was rebased --onto trunk f73bb49bca to drop the now-merged parent commits, and the PR's base branch was switched from the (now-deleted) feature branch to trunk. Tests + build re-verified clean against the new base.
Unaddressed: none.
CI: all 62 required checks passing.
Fixes RSM-3608. Follow-up to #48986 (this PR is stacked on top of
raven/rsm-3591-ai-answer-blockand targets it as base — once #48986 lands on trunk, this branch can be rebased onto trunk).Why
When the AI Answer block ships, the site-wide
jetpack_search_ai_answers_enabledoption will simultaneously control two unrelated decisions: whether the instant-search overlay fires AI Answers (where the option is the right gate — the overlay is the default UX on any search page), and whether an embeddedjetpack-search/ai-answerblock that an author explicitly inserted should render (where the block's presence in saved post content already is the opt-in signal). That coupling was flagged in #48986 (review).This PR keeps the option's role for the overlay and removes it from the block path. To opt out of AI Answers for an embedded surface, an author removes the block — not flips a global flag.
Proposed changes
projects/packages/search/src/search-blocks/blocks/ai-answer/render.php— drop theAI_Answers::is_enabled()early return. The block renders whenever it's present in post content.projects/packages/search/src/search-blocks/class-search-blocks.phpbuild_initial_state()— drop theaiAnswersEnabledseed key; no block-side consumer reads it anymore.projects/packages/search/src/search-blocks/store/index.js:aiAnswersEnabledguards inactions.fetchAiAnswer()andactions.showExtendedAiAnswer(). The fetch is still gated by theaiBlockPresentmodule flag (set when the block mounts) plus the standard query-length + same-query memo.aiAnswersEnabledclause from theaiPanelHiddengetter — visible status alone determines panel visibility.test_disabled_renders_nothingPHP case; addtest_renders_panel_wrapper_independent_of_site_optionthat exercises render with the option off / unset / on. Drop the matching JS tests; the rest stop settingstate.aiAnswersEnabledsince it no longer exists.Overlay behaviour is unchanged —
class-helper.phpstill localizesaiAnswersEnabledfor the overlay, andsearch-app.jsx::getAiAnswerstill consults it.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. Same
POST https://public-api.wordpress.com/wpcom/v2/ai/agent/jetpack-workflow-search_summarizerendpoint, same request shape, same site/query/filter payload. The only change is when the block's view bundle decides to call it — block presence on a page now suffices, the site option no longer overrides it.Verification
The change is functional (a removed gate) rather than visual. Verified live on the raven docker env (
https://jp-raven.jurassic.tube/):Server-side render is independent of the option
(On
trunk+ parent PR #48986, the samecurlagainst an option-off site returns0— the gate was emitting nothing.)Client-side: AI fetch fires + panel renders with the option off
Unit tests
Testing instructions
pnpm jetpack build packages/my-jetpack && pnpm jetpack build plugins/jetpack && pnpm jetpack build packages/search && pnpm jetpack build plugins/search.Verify each acceptance criterion from the issue:
wp option update jetpack_search_ai_answers_enabled 0, visiting the page with?q=wordpressstill renders the AI Answer panel and the SSE fetch still fires.wp option update jetpack_search_ai_answers_enabled 0, the instant-search overlay (on the default/?s=wordpressroute) still does NOT fire its AI Answers. (Unchanged behaviour — the overlay still readswindow.SERVER_OBJECT_NAME.aiAnswersEnabledfromclass-helper.php.)