Skip to content

Commit 4815e7d

Browse files
authored
fix: site builder overlay only renders on main AI Agent page (#511) (#515)
The overlay was activating on all admin pages (Changes, Abilities, etc.) whenever isFreshInstall was true, blocking those pages entirely. Two fixes: 1. Add isMainAgentPage() guard — checks window.pagenow for 'toplevel_page_gratis-ai-agent', falls back to URL ?page param. 2. Fix window reference: read gratisAiAgentSiteBuilder.siteBuilderMode (the actual PHP-localized object) instead of the non-existent gratisAiAgentData.site_builder_mode. The overlay now only activates and renders when both siteBuilderMode is true AND the user is on the main AI Agent admin page. Closes #511
1 parent c7cce2d commit 4815e7d

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

build/floating-widget.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'b16c2d9f8102488c822f');
1+
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '335c0ca4cc2d6cbf8536');

build/floating-widget.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/floating-widget/index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ function FloatingWidget() {
8181
}, [ setPageContext ] );
8282

8383
// Activate site builder mode when the PHP layer signals it (t060/t062).
84+
// Only activate on the main AI Agent page — not on Changes, Abilities, or
85+
// other admin pages where the overlay would block unrelated content (#511).
8486
useEffect( () => {
85-
if ( window.gratisAiAgentData?.site_builder_mode ) {
87+
if (
88+
window.gratisAiAgentSiteBuilder?.siteBuilderMode &&
89+
isMainAgentPage()
90+
) {
8691
setSiteBuilderMode( true );
8792
}
8893
}, [ setSiteBuilderMode ] );
8994

9095
// Site builder full-screen overlay takes priority over normal FAB/panel.
91-
if ( isSiteBuilderMode ) {
96+
// Guard: only render on the main AI Agent page.
97+
if ( isSiteBuilderMode && isMainAgentPage() ) {
9298
return <SiteBuilderOverlay />;
9399
}
94100

@@ -100,6 +106,33 @@ function FloatingWidget() {
100106
);
101107
}
102108

109+
/**
110+
* Determine whether the current admin page is the main AI Agent page.
111+
*
112+
* The site builder overlay must only render on the main AI Agent page
113+
* (slug: `gratis-ai-agent`). On other admin pages — Changes, Abilities,
114+
* Settings, or any unrelated WordPress page — the overlay must not appear
115+
* even when `siteBuilderMode` is true in the store (#511).
116+
*
117+
* WordPress sets `window.pagenow` to the page slug for top-level menu pages
118+
* (e.g. `toplevel_page_gratis-ai-agent`) and `window.adminpage` to the
119+
* hook suffix. We also check the URL `page` query param as a fallback.
120+
*
121+
* @return {boolean} True only when on the main AI Agent admin page.
122+
*/
123+
function isMainAgentPage() {
124+
const MAIN_PAGE_SLUG = 'gratis-ai-agent';
125+
126+
// WordPress sets pagenow to `toplevel_page_{slug}` for top-level menu pages.
127+
if ( window.pagenow ) {
128+
return window.pagenow === 'toplevel_page_' + MAIN_PAGE_SLUG;
129+
}
130+
131+
// Fallback: check the URL `page` query parameter.
132+
const urlParams = new URLSearchParams( window.location.search );
133+
return urlParams.get( 'page' ) === MAIN_PAGE_SLUG;
134+
}
135+
103136
/**
104137
* Gather structured context about the current WordPress admin page.
105138
*

0 commit comments

Comments
 (0)