From 66585de2aa573ba52081ef482df6a8d4d892eed7 Mon Sep 17 00:00:00 2001 From: Douglas Date: Thu, 17 Sep 2026 12:42:19 -0300 Subject: [PATCH 1/2] My Jetpack: retire the wp-build flag and the legacy dashboard bundle The dashboard now always renders through wp-build. The webpack build keeps two entries: the onboarding takeover, which hides all wp-admin chrome and stays on its own bundle, and the async notification bubble. The React state stays on the `my_jetpack_main_app` handle, now script-less. Boost depends on that name from its own admin page, so released Boost versions keep resolving it without downloading the dashboard bundle. The Features tab flag no longer requires the retired wp-build flag. Co-Authored-By: Claude Opus 5 (1M context) --- projects/packages/my-jetpack/README.md | 6 +- projects/packages/my-jetpack/_inc/admin.jsx | 40 ---- projects/packages/my-jetpack/_inc/app.jsx | 2 +- .../my-jetpack/_inc/design-tokens.scss | 2 +- .../packages/my-jetpack/_inc/onboarding.jsx | 29 +++ .../my-jetpack/_inc/style.module.scss | 46 +---- .../my-jetpack/routes/dashboard/route.scss | 12 +- .../my-jetpack/routes/dashboard/stage.tsx | 4 +- .../my-jetpack/src/class-initializer.php | 131 ++++-------- .../my-jetpack/tests/php/Initializer_Test.php | 16 +- .../tests/php/Initializer_Wp_Build_Test.php | 186 +++++++----------- .../php/Register_Wp_Build_Polyfills_Test.php | 58 ------ .../my-jetpack/tests/php/Script_Data_Test.php | 2 - .../packages/my-jetpack/webpack.config.js | 2 +- .../_inc/lib/Akismet_Admin_Chrome_Test.php | 2 - tools/performance/scripts/scenarios.js | 4 +- 16 files changed, 157 insertions(+), 385 deletions(-) delete mode 100644 projects/packages/my-jetpack/_inc/admin.jsx create mode 100644 projects/packages/my-jetpack/_inc/onboarding.jsx delete mode 100644 projects/packages/my-jetpack/tests/php/Register_Wp_Build_Polyfills_Test.php diff --git a/projects/packages/my-jetpack/README.md b/projects/packages/my-jetpack/README.md index 003c945cff4b..8273f165c77f 100644 --- a/projects/packages/my-jetpack/README.md +++ b/projects/packages/my-jetpack/README.md @@ -35,7 +35,8 @@ To disable the licensing UI at `/wp-admin/admin.php?page=my-jetpack#/add-license #### React Frontend (`_inc/`) -- **Main App** (`admin.jsx`): Entry point with React Router setup +- **Main App** (`app.jsx`): React Router setup, rendered by the wp-build route in `routes/dashboard/` +- **Onboarding** (`onboarding.jsx`): Webpack entry for the full-screen onboarding takeover - **Components** (`components/`): Reusable UI components for product cards, screens, and interstitials - **Data Layer** (`data/`): Custom hooks and API integration using React Query (see [Data Layer Documentation](./_inc/data/README.md)) - **Context** (`context/`): Global state management for notices and values @@ -130,7 +131,8 @@ To disable the licensing UI at `/wp-admin/admin.php?page=my-jetpack#/add-license ### React Files -- `_inc/admin.jsx` - Main React application entry point +- `_inc/app.jsx` - Main React application, rendered by `routes/dashboard/stage.tsx` +- `_inc/onboarding.jsx` - Onboarding takeover entry point - `_inc/providers.tsx` - Context providers wrapper - `_inc/constants.ts` - Route definitions and constants - `_inc/components/my-jetpack-screen/` - Main dashboard screen diff --git a/projects/packages/my-jetpack/_inc/admin.jsx b/projects/packages/my-jetpack/_inc/admin.jsx deleted file mode 100644 index d36b4841323e..000000000000 --- a/projects/packages/my-jetpack/_inc/admin.jsx +++ /dev/null @@ -1,40 +0,0 @@ -/** - * External dependencies - */ -import { createRoot } from '@wordpress/element'; -/** - * Internal dependencies - */ -import App from './app'; -import OnboardingScreen from './components/onboarding-screen'; -import Providers from './providers'; -import './design-tokens.scss'; - -const MyJetpack = () => { - const container = document.getElementById( 'my-jetpack-container' ); - - // Legacy-only; see Initializer::is_onboarding_takeover(). - if ( container?.dataset?.route === 'onboarding' ) { - return ( - - - - ); - } - - return ; -}; - -/** - * The initial renderer function. - */ -function render() { - const container = document.getElementById( 'my-jetpack-container' ); - if ( null === container ) { - return; - } - - createRoot( container ).render( ); -} - -render(); diff --git a/projects/packages/my-jetpack/_inc/app.jsx b/projects/packages/my-jetpack/_inc/app.jsx index 5cff8334ff78..90c006014265 100644 --- a/projects/packages/my-jetpack/_inc/app.jsx +++ b/projects/packages/my-jetpack/_inc/app.jsx @@ -49,7 +49,7 @@ function ScrollToTop() { } /** - * The My Jetpack app tree, shared by the legacy entry and the wp-build stage. + * The My Jetpack app tree, rendered by the wp-build stage. * * @return {import('react').ReactElement} The App component. */ diff --git a/projects/packages/my-jetpack/_inc/design-tokens.scss b/projects/packages/my-jetpack/_inc/design-tokens.scss index 25880970ba87..ad4653160e3c 100644 --- a/projects/packages/my-jetpack/_inc/design-tokens.scss +++ b/projects/packages/my-jetpack/_inc/design-tokens.scss @@ -1,4 +1,4 @@ // @wordpress/ui design tokens (--wpds-*), or its var() lookups resolve empty. -// Legacy entry only: dependency extraction misreads a JS import as a script +// Onboarding entry only: dependency extraction misreads a JS import as a script // handle, and wp-build leaves a bare `@import` to 404 against /wp-admin/. @import "@wordpress/theme/design-tokens.css"; diff --git a/projects/packages/my-jetpack/_inc/onboarding.jsx b/projects/packages/my-jetpack/_inc/onboarding.jsx new file mode 100644 index 000000000000..2fda6595f698 --- /dev/null +++ b/projects/packages/my-jetpack/_inc/onboarding.jsx @@ -0,0 +1,29 @@ +/** + * External dependencies + */ +import { createRoot } from '@wordpress/element'; +/** + * Internal dependencies + */ +import './style.module.scss'; +import OnboardingScreen from './components/onboarding-screen'; +import Providers from './providers'; +import './design-tokens.scss'; + +/** + * Render the onboarding takeover; the dashboard renders through wp-build. + */ +function render() { + const container = document.getElementById( 'my-jetpack-container' ); + if ( null === container ) { + return; + } + + createRoot( container ).render( + + + + ); +} + +render(); diff --git a/projects/packages/my-jetpack/_inc/style.module.scss b/projects/packages/my-jetpack/_inc/style.module.scss index 8e7bdac8c253..7a3c2ca76989 100644 --- a/projects/packages/my-jetpack/_inc/style.module.scss +++ b/projects/packages/my-jetpack/_inc/style.module.scss @@ -1,51 +1,9 @@ -@use "@automattic/jetpack-base-styles/admin-page-layout" as *; - :global { - // Apply the shared admin-page-layout mixin so the main My Jetpack page - // (sticky header, internally scrollable middle, JetpackFooter pinned at - // viewport bottom) matches Boost / Protect / VideoPress / Search / - // Newsletter / Publicize / Backup / Jetpack network admin / AI. - - // Excluded: My Jetpack's `.jetpack-admin-full-screen` interstitial mode - // (e.g. the `step=onboarding` "Supercharge my site" screen), which hides - // the admin bar and takes over the whole viewport; its existing rules - // (further down in this file) override wp-admin chrome directly and - // should keep doing so. The class lives on `` itself — added - // server-side via `admin_body_class` for `step=onboarding` and - // client-side by the `useFullScreen` hook for other full-screen routes — - // so the opt-out matches it as a sibling class on ``, not as a - // descendant via `:has()`. - body.jetpack_page_my-jetpack:not(.jetpack-admin-full-screen) { - - @include jetpack-admin-page-layout; - - // Reserve space for the scrollable middle's vertical scrollbar so toggling - // between search results and category browse — which changes the content - // height, and thus whether the scrollbar is present — doesn't shift the - // layout sideways. Most noticeable on Firefox / platforms with classic - // (space-consuming) scrollbars; a no-op where unsupported. The selector - // mirrors the "scrollable middle" defined by jetpack-admin-page-layout. - .jp-admin-page__page > :not(:first-child):not(.jetpack-footer) { - scrollbar-gutter: stable; - } - } - + // The onboarding takeover's container. The dashboard's layout + // lives in routes/dashboard/route.scss. #my-jetpack-container { height: 100%; - - &:has(.my-jetpack-deprecate-notice-title) { - - .jetpack-deprecation-notice-link { - color: inherit; - font-weight: 600; - padding-right: 5px; - } - } - - .my-jetpack-deprecate-notice-title { - font-weight: 600; - } } #wpbody-content { diff --git a/projects/packages/my-jetpack/routes/dashboard/route.scss b/projects/packages/my-jetpack/routes/dashboard/route.scss index 542e8765c6f0..0b68c150d6fb 100644 --- a/projects/packages/my-jetpack/routes/dashboard/route.scss +++ b/projects/packages/my-jetpack/routes/dashboard/route.scss @@ -5,13 +5,9 @@ // Onboarding keeps its own full-viewport rules in _inc/style.module.scss. body.jetpack_page_my-jetpack:not(.jetpack-admin-full-screen) { - // This re-emits jetpack-admin-page-layout, which _inc/style.module.scss also - // includes on the same selector at the same specificity. Keep the two in sync: - // when they conflict, source order decides, and that order is not guaranteed. @include jetpack-admin-page-layout-wp-build; - // Matches legacy: onboarding-screen/styles.module.scss has a `:global(body)` - // rule that leaks into every My Jetpack page via the shared webpack bundle. + // The Jetpack font stack onboarding-screen/styles.module.scss sets on `body`. // Inlined, not imported — that file is a component module, not a partial. font-family: -apple-system, @@ -28,13 +24,13 @@ body.jetpack_page_my-jetpack:not(.jetpack-admin-full-screen) { Arial, sans-serif; - // Boot's stage sets #1e1e1e; legacy inherits wp-admin's body color. + // wp-admin's body color, not the #1e1e1e boot's stage sets. .boot-layout__stage { color: #3c434a; } - // Mirrors the legacy path: keep the scrollable middle's gutter reserved - // so content-height changes don't shift the layout sideways. + // Keep the scrollable middle's gutter reserved so content-height changes + // don't shift the layout sideways. .jp-admin-page__page > :not(:first-child):not(.jetpack-footer) { scrollbar-gutter: stable; } diff --git a/projects/packages/my-jetpack/routes/dashboard/stage.tsx b/projects/packages/my-jetpack/routes/dashboard/stage.tsx index 74bebd25191c..a344a3c46766 100644 --- a/projects/packages/my-jetpack/routes/dashboard/stage.tsx +++ b/projects/packages/my-jetpack/routes/dashboard/stage.tsx @@ -4,8 +4,8 @@ import './route.scss'; /** * Boot stage for the My Jetpack dashboard. * - * Renders the same tree as the legacy entry, `HashRouter` included — boot - * reads its path from `?p=`, never the hash, so `#/…` deep links still resolve. + * Keeps the app's `HashRouter` — boot reads its path from `?p=`, never the + * hash, so `#/…` deep links still resolve. * * @return The My Jetpack app. */ diff --git a/projects/packages/my-jetpack/src/class-initializer.php b/projects/packages/my-jetpack/src/class-initializer.php index 26992eb3a3f2..c8d133e07009 100644 --- a/projects/packages/my-jetpack/src/class-initializer.php +++ b/projects/packages/my-jetpack/src/class-initializer.php @@ -48,21 +48,21 @@ class Initializer { const PACKAGE_VERSION = '6.3.0'; /** - * Feature flag that opts a site into the wp-build My Jetpack dashboard. + * Feature flag that swaps the My Jetpack Products tab for a Features tab. */ - const WP_BUILD_FEATURE_FLAG = 'my-jetpack-wp-build'; + const FEATURES_TAB_FEATURE_FLAG = 'my-jetpack-features-tab'; /** - * Feature flag that swaps the My Jetpack Products tab for a Features tab. + * Handle for the classic script that carries the React initial state. + * + * Plugins that render My Jetpack components on their own pages (Boost) depend on this name. */ - const FEATURES_TAB_FEATURE_FLAG = 'my-jetpack-features-tab'; + const DATA_SCRIPT_HANDLE = 'my_jetpack_main_app'; /** - * Handle for the classic script that carries the React initial state on the - * wp-build path. The dashboard is a script module there, so there is no - * classic bundle handle to attach inline data to. + * Handle for the webpack bundle that renders the onboarding takeover. */ - const DATA_SCRIPT_HANDLE = 'my-jetpack-data'; + const ONBOARDING_SCRIPT_HANDLE = 'my_jetpack_onboarding'; /** * The wp-build page ID, which the generated enqueue check expects as the screen ID. @@ -334,51 +334,25 @@ public static function can_use_analytics() { * @return void */ public static function register_feature_flags() { - Feature_Flags::register( - self::WP_BUILD_FEATURE_FLAG, - array( - 'default' => false, - 'description' => 'Serve the My Jetpack dashboard through the wp-build pipeline.', - 'owner' => 'my-jetpack', - ) - ); - Feature_Flags::register( self::FEATURES_TAB_FEATURE_FLAG, array( 'default' => false, - 'description' => 'Replace the My Jetpack Products tab with a Features tab. Requires my-jetpack-wp-build.', + 'description' => 'Replace the My Jetpack Products tab with a Features tab.', 'owner' => 'my-jetpack', ) ); } - /** - * Whether this site renders My Jetpack through wp-build. - * - * Defaults off while the port is verified; enable it with - * `wp companion feature-flag enable my-jetpack-wp-build`. - * - * @since 6.3.0 - * - * @return bool - */ - public static function is_modernized() { - return Feature_Flags::is_enabled( self::WP_BUILD_FEATURE_FLAG ); - } - /** * Whether the dashboard shows a Features tab in place of the Products tab. * - * Also requires `my-jetpack-wp-build`, but is site-wide: a request that falls back to the - * legacy bundle, such as the onboarding takeover, shows the Features tab too. - * * @since $$next-version$$ * * @return bool */ public static function is_features_tab_enabled() { - return self::is_modernized() && Feature_Flags::is_enabled( self::FEATURES_TAB_FEATURE_FLAG ); + return Feature_Flags::is_enabled( self::FEATURES_TAB_FEATURE_FLAG ); } /** @@ -493,27 +467,25 @@ public static function restore_screen_id_after_wp_build() { * @return bool */ public static function should_load_wp_build() { - return self::is_modernized() && self::is_my_jetpack_admin_request() && ! self::is_onboarding_takeover(); + return self::is_my_jetpack_admin_request() && ! self::is_onboarding_takeover(); } /** - * Whether this request renders through wp-build rather than the legacy bundle. + * Whether this request renders the dashboard through wp-build. * - * Checks the render function too: a flag registered after `admin_menu` priority 1 leaves - * wp-build unloaded, and the request would otherwise get neither bundle. + * The generated render function is missing where the package was never built. * * @since 6.3.0 * * @return bool */ public static function should_render_wp_build() { - return self::is_modernized() - && ! self::is_onboarding_takeover() + return ! self::is_onboarding_takeover() && function_exists( 'jetpack_my_jetpack_my_jetpack_dashboard_wp_admin_render_page' ); } /** - * Load wp-build for the My Jetpack page when the site has opted in. + * Load wp-build for the My Jetpack dashboard. * * @since 6.3.0 * @@ -559,42 +531,12 @@ public static function load_wp_build( $build_index ) { ); } - /** - * Register polyfills for the wp-notices / wp-private-apis / wp-rich-text / wp-theme - * handles the My Jetpack app bundle depends on but WP < 7.0 does not ship (or ships - * with an incomplete allowlist). - * - * `wp-rich-text` is needed because the bundle reaches `@wordpress/dataviews` (via - * `@wordpress/ui`), whose dataform controls unlock rich-text's `privateApis` at module - * scope. WP 6.9 exports none, so without the polyfill the bundle throws "Cannot unlock - * an undefined object" and the page renders blank. - * - * @return void - */ - public static function register_wp_build_polyfills() { - if ( ! class_exists( WP_Build_Polyfills::class ) ) { - return; - } - - WP_Build_Polyfills::register( - 'my-jetpack', - array( 'wp-notices', 'wp-private-apis', 'wp-rich-text', 'wp-theme' ) - ); - } - /** * Enqueue admin page assets. * * @return void */ public static function enqueue_scripts() { - // Register the wp-build-polyfills shim before the extension hook below or - // the app script can enqueue against wp-theme / wp-private-apis / wp-notices. - // WP_Build_Polyfills registers synchronously on its first caller, so calling - // it after a hook consumer would leave our handles recorded but unregistered - // for this request. - self::register_wp_build_polyfills(); - /** * Fires after the My Jetpack page is initialized. * Allows for enqueuing additional scripts only on the My Jetpack page. @@ -604,30 +546,26 @@ public static function enqueue_scripts() { do_action( 'myjetpack_enqueue_scripts' ); add_filter( 'jetpack_admin_js_script_data', array( __CLASS__, 'add_script_data' ) ); - if ( self::should_render_wp_build() ) { - // wp-build enqueues the app itself; this empty handle exists only to - // print the initial state before boot runs on DOMContentLoaded. - $data_handle = self::DATA_SCRIPT_HANDLE; - wp_register_script( $data_handle, false, array(), self::PACKAGE_VERSION, true ); - wp_enqueue_script( $data_handle ); - - // The i18n loader is registered on every admin page but only enqueued - // when depended on; the esbuild bundles don't pull it in. - if ( wp_script_is( 'wp-jp-i18n-loader', 'registered' ) ) { - wp_enqueue_script( 'wp-jp-i18n-loader' ); - } - } else { - $data_handle = 'my_jetpack_main_app'; + // Script-less: it only prints the state below, before the dashboard's boot runs on DOMContentLoaded. + $data_handle = self::DATA_SCRIPT_HANDLE; + wp_register_script( $data_handle, false, array(), self::PACKAGE_VERSION, true ); + wp_enqueue_script( $data_handle ); + + if ( self::is_my_jetpack_admin_request() && self::is_onboarding_takeover() ) { Assets::register_script( - $data_handle, - '../build/index.js', + self::ONBOARDING_SCRIPT_HANDLE, + '../build/onboarding.js', __FILE__, array( - 'enqueue' => true, - 'in_footer' => true, - 'textdomain' => 'jetpack-my-jetpack', + 'dependencies' => array( $data_handle ), + 'enqueue' => true, + 'in_footer' => true, + 'textdomain' => 'jetpack-my-jetpack', ) ); + } elseif ( self::should_render_wp_build() && wp_script_is( 'wp-jp-i18n-loader', 'registered' ) ) { + // Registered on every admin page but only enqueued when depended on; the esbuild bundles don't pull it in. + wp_enqueue_script( 'wp-jp-i18n-loader' ); } $modules = new Modules(); @@ -913,15 +851,14 @@ public static function admin_page() { // No connection check needed here: admin_init() has already redirected connected users // away from onboarding. Availability is re-checked inside the helper on purpose — this // render can run even when that redirect did not. - $is_onboarding = self::is_onboarding_takeover(); + if ( self::is_onboarding_takeover() ) { + echo '
'; + return; + } if ( self::should_render_wp_build() ) { jetpack_my_jetpack_my_jetpack_dashboard_wp_admin_render_page(); // @phan-suppress-current-line PhanUndeclaredFunction -- should_render_wp_build() checks function_exists(); defined in the generated build/pages/, which Phan excludes. - return; } - - // Add data attribute for onboarding, otherwise render normal container - echo '
'; } /** diff --git a/projects/packages/my-jetpack/tests/php/Initializer_Test.php b/projects/packages/my-jetpack/tests/php/Initializer_Test.php index 73fe3826012e..3846f9644c32 100644 --- a/projects/packages/my-jetpack/tests/php/Initializer_Test.php +++ b/projects/packages/my-jetpack/tests/php/Initializer_Test.php @@ -129,24 +129,23 @@ public function test_get_onboarding_redirect_args( $step, $is_connected, $onboar } /** - * The admin page marks the container with the onboarding route when - * onboarding is requested and available. + * The admin page renders the onboarding container when onboarding is requested and available. */ - public function test_admin_page_renders_onboarding_route_when_available() { + public function test_admin_page_renders_the_onboarding_container_when_available() { $_GET['step'] = 'onboarding'; ob_start(); Initializer::admin_page(); $output = ob_get_clean(); - $this->assertStringContainsString( 'data-route="onboarding"', $output ); + $this->assertStringContainsString( 'id="my-jetpack-container"', $output ); } /** - * The admin page never marks the container with the onboarding route on - * WordPress.com Simple sites, even when the redirect did not run. + * The admin page never renders the onboarding container on WordPress.com Simple sites, + * even when the redirect did not run. */ - public function test_admin_page_does_not_render_onboarding_route_on_wpcom_simple() { + public function test_admin_page_does_not_render_the_onboarding_container_on_wpcom_simple() { Constants::set_constant( 'IS_WPCOM', true ); $_GET['step'] = 'onboarding'; @@ -154,8 +153,7 @@ public function test_admin_page_does_not_render_onboarding_route_on_wpcom_simple Initializer::admin_page(); $output = ob_get_clean(); - $this->assertStringContainsString( 'id="my-jetpack-container"', $output ); - $this->assertStringNotContainsString( 'data-route', $output ); + $this->assertStringNotContainsString( 'my-jetpack-container', $output ); } /** diff --git a/projects/packages/my-jetpack/tests/php/Initializer_Wp_Build_Test.php b/projects/packages/my-jetpack/tests/php/Initializer_Wp_Build_Test.php index 64da6529b495..46dfee1936ce 100644 --- a/projects/packages/my-jetpack/tests/php/Initializer_Wp_Build_Test.php +++ b/projects/packages/my-jetpack/tests/php/Initializer_Wp_Build_Test.php @@ -1,6 +1,6 @@ assertSame( false, Feature_Flags::get( Initializer::WP_BUILD_FEATURE_FLAG )['default'] ?? null ); - $this->assertFalse( Initializer::is_modernized() ); - } - - /** - * The flag's per-flag filter turns it on. + * The Features tab is off unless its flag is on. * * @return void */ - public function test_modernization_flag_turns_it_on() { + public function test_features_tab_follows_its_flag() { Initializer::register_feature_flags(); - add_filter( self::FLAG_FILTER, '__return_true' ); - $this->assertTrue( Initializer::is_modernized() ); - } - - /** - * The Features tab needs its own flag and the wp-build flag. - * - * @return void - */ - public function test_features_tab_requires_both_flags() { - Initializer::register_feature_flags(); - - $this->assertFalse( Initializer::is_features_tab_enabled(), 'Both flags off.' ); + $this->assertFalse( Initializer::is_features_tab_enabled() ); $this->assertNull( Initializer::get_products_section() ); add_filter( self::FEATURES_TAB_FLAG_FILTER, '__return_true' ); - $this->assertFalse( Initializer::is_features_tab_enabled(), 'Features tab flag only.' ); - - add_filter( self::FLAG_FILTER, '__return_true' ); - $this->assertTrue( Initializer::is_features_tab_enabled(), 'Both flags on.' ); + $this->assertTrue( Initializer::is_features_tab_enabled() ); $this->assertSame( array( 'slug' => 'features', @@ -87,9 +54,6 @@ public function test_features_tab_requires_both_flags() { ), Initializer::get_products_section() ); - - remove_all_filters( self::FEATURES_TAB_FLAG_FILTER ); - $this->assertFalse( Initializer::is_features_tab_enabled(), 'wp-build flag only.' ); } /** @@ -103,7 +67,7 @@ public function test_init_registers_the_flag_where_my_jetpack_is_off() { Initializer::init(); $this->assertFalse( Initializer::should_initialize() ); - $this->assertNotNull( Feature_Flags::get( Initializer::WP_BUILD_FEATURE_FLAG ) ); + $this->assertNotNull( Feature_Flags::get( Initializer::FEATURES_TAB_FEATURE_FLAG ) ); } /** @@ -135,16 +99,13 @@ public function test_onboarding_request_detection() { } /** - * Only the flagged My Jetpack dashboard request loads wp-build, and with it the polyfills. + * Only the My Jetpack dashboard request loads wp-build, and with it the polyfills. * * @return void */ - public function test_should_load_wp_build_is_scoped_to_the_flagged_dashboard_request() { + public function test_should_load_wp_build_is_scoped_to_the_dashboard_request() { $_GET['page'] = 'my-jetpack'; - $this->assertFalse( Initializer::should_load_wp_build(), 'Flag off.' ); - - add_filter( self::FLAG_FILTER, '__return_true' ); - $this->assertTrue( Initializer::should_load_wp_build(), 'Flagged dashboard request.' ); + $this->assertTrue( Initializer::should_load_wp_build(), 'Dashboard request.' ); $_GET['page'] = 'jetpack'; $this->assertFalse( Initializer::should_load_wp_build(), 'Another admin page.' ); @@ -211,7 +172,7 @@ static function () use ( &$id_after ) { } /** - * Flag off, the page keeps the legacy container even where the render function exists. + * The dashboard hands off to the wp-build render function. * * @runInSeparateProcess * @preserveGlobalState disabled @@ -220,37 +181,26 @@ static function () use ( &$id_after ) { */ #[RunInSeparateProcess] #[PreserveGlobalState( false )] - public function test_admin_page_renders_the_legacy_container_when_the_flag_is_off() { + public function test_admin_page_renders_through_wp_build_when_loaded() { require_once __DIR__ . '/stubs/wp-build-render-page.php'; $html = $this->render_admin_page(); - $this->assertStringContainsString( 'id="my-jetpack-container"', $html ); - $this->assertStringNotContainsString( 'my-jetpack-dashboard-wp-admin-app', $html ); + $this->assertStringContainsString( 'id="my-jetpack-dashboard-wp-admin-app"', $html ); + $this->assertStringNotContainsString( 'my-jetpack-container', $html ); } /** - * Flag on, the page hands off to the wp-build render function. - * - * @runInSeparateProcess - * @preserveGlobalState disabled + * An unbuilt checkout has no render function to call, and must not fatal. * * @return void */ - #[RunInSeparateProcess] - #[PreserveGlobalState( false )] - public function test_admin_page_renders_through_wp_build_when_loaded() { - require_once __DIR__ . '/stubs/wp-build-render-page.php'; - add_filter( self::FLAG_FILTER, '__return_true' ); - - $html = $this->render_admin_page(); - - $this->assertStringContainsString( 'id="my-jetpack-dashboard-wp-admin-app"', $html ); - $this->assertStringNotContainsString( 'my-jetpack-container', $html ); + public function test_admin_page_renders_nothing_without_the_wp_build_output() { + $this->assertSame( '', $this->render_admin_page() ); } /** - * Flag on, onboarding still takes the legacy path. + * Onboarding renders its own container even where wp-build is loaded. * * @runInSeparateProcess * @preserveGlobalState disabled @@ -259,14 +209,13 @@ public function test_admin_page_renders_through_wp_build_when_loaded() { */ #[RunInSeparateProcess] #[PreserveGlobalState( false )] - public function test_admin_page_keeps_onboarding_on_the_legacy_container() { + public function test_admin_page_renders_the_onboarding_container_for_the_takeover() { require_once __DIR__ . '/stubs/wp-build-render-page.php'; - add_filter( self::FLAG_FILTER, '__return_true' ); $_GET['step'] = 'onboarding'; $html = $this->render_admin_page(); - $this->assertStringContainsString( 'data-route="onboarding"', $html ); + $this->assertStringContainsString( 'id="my-jetpack-container"', $html ); $this->assertStringNotContainsString( 'my-jetpack-dashboard-wp-admin-app', $html ); } @@ -282,14 +231,14 @@ private function render_admin_page() { } /** - * Stub the built bundle's dependencies, or `failOnNotice` fails the enqueue. + * Stub the onboarding bundle's dependencies, or `failOnNotice` fails the enqueue. * * Unbuilt checkouts (CI) declare none. * * @return void */ - private function stub_legacy_bundle_dependencies() { - $asset_file = dirname( __DIR__, 2 ) . '/build/index.asset.php'; + private function stub_onboarding_bundle_dependencies() { + $asset_file = dirname( __DIR__, 2 ) . '/build/onboarding.asset.php'; if ( ! file_exists( $asset_file ) ) { return; @@ -305,8 +254,25 @@ private function stub_legacy_bundle_dependencies() { } /** - * With the flag off, every site keeps the legacy bundle. This is the safety - * property every bundling plugin depends on. + * Assert the three state payloads landed on the script-less data handle. + * + * @return void + */ + private function assert_state_is_on_the_data_handle() { + $this->assertTrue( wp_script_is( Initializer::DATA_SCRIPT_HANDLE, 'enqueued' ) ); + $this->assertFalse( wp_scripts()->registered[ Initializer::DATA_SCRIPT_HANDLE ]->src ); + + // wp_localize_script() writes to `data`; Connection_Initial_State uses an inline `before`. + $localized = wp_scripts()->get_data( Initializer::DATA_SCRIPT_HANDLE, 'data' ); + $this->assertStringContainsString( 'myJetpackInitialState', $localized ); + $this->assertStringContainsString( 'myJetpackRest', $localized ); + + $before = implode( '', (array) wp_scripts()->get_data( Initializer::DATA_SCRIPT_HANDLE, 'before' ) ); + $this->assertStringContainsString( 'JP_CONNECTION_INITIAL_STATE', $before ); + } + + /** + * The dashboard is a script module, so its state goes on a data handle with no bundle behind it. * * Runs isolated: enqueue_scripts() makes a real is_connected() call, which sets * a process-wide flag WorDBless teardown cannot reset (see Initializer_Test). @@ -318,19 +284,25 @@ private function stub_legacy_bundle_dependencies() { */ #[RunInSeparateProcess] #[PreserveGlobalState( false )] - public function test_enqueue_scripts_registers_the_legacy_bundle_when_the_flag_is_off() { + public function test_enqueue_scripts_puts_the_dashboard_state_on_the_data_handle() { $_GET['page'] = 'my-jetpack'; - $this->stub_legacy_bundle_dependencies(); + + // Stands in for the generated build/pages/ render function the dashboard gates on. + require_once __DIR__ . '/stubs/wp-build-render-page.php'; + + wp_register_script( 'wp-jp-i18n-loader', 'https://example.org/i18n.js', array(), '1.0.0', true ); Initializer::enqueue_scripts(); - $this->assertTrue( wp_script_is( 'my_jetpack_main_app', 'registered' ) ); - $this->assertFalse( wp_script_is( Initializer::DATA_SCRIPT_HANDLE, 'registered' ) ); + $this->assert_state_is_on_the_data_handle(); + $this->assertFalse( wp_script_is( Initializer::ONBOARDING_SCRIPT_HANDLE, 'registered' ) ); + + // The esbuild bundles don't depend on the loader, so it needs enqueueing by hand. + $this->assertTrue( wp_script_is( 'wp-jp-i18n-loader', 'enqueued' ) ); } /** - * A flag added after admin_menu must not cost the request its legacy bundle; - * Boost depends on that handle. + * Onboarding loads its webpack bundle after the state it reads. * * @runInSeparateProcess * @preserveGlobalState disabled @@ -339,26 +311,23 @@ public function test_enqueue_scripts_registers_the_legacy_bundle_when_the_flag_i */ #[RunInSeparateProcess] #[PreserveGlobalState( false )] - public function test_enqueue_scripts_keeps_the_legacy_bundle_when_wp_build_never_loaded() { + public function test_enqueue_scripts_loads_the_onboarding_bundle_for_the_takeover() { $_GET['page'] = 'my-jetpack'; - $this->stub_legacy_bundle_dependencies(); - - // The loader runs on admin_menu priority 1 — before this filter exists. - Initializer::maybe_load_wp_build(); - add_filter( self::FLAG_FILTER, '__return_true' ); + $_GET['step'] = 'onboarding'; + $this->stub_onboarding_bundle_dependencies(); Initializer::enqueue_scripts(); - $this->assertTrue( wp_script_is( 'my_jetpack_main_app', 'registered' ) ); - $this->assertFalse( wp_script_is( Initializer::DATA_SCRIPT_HANDLE, 'registered' ) ); + $this->assert_state_is_on_the_data_handle(); + $this->assertTrue( wp_script_is( Initializer::ONBOARDING_SCRIPT_HANDLE, 'enqueued' ) ); + $this->assertContains( + Initializer::DATA_SCRIPT_HANDLE, + wp_scripts()->registered[ Initializer::ONBOARDING_SCRIPT_HANDLE ]->deps + ); } /** - * With wp-build loaded, the three state payloads have to move to the data handle — - * the app is a script module there, so the legacy handle never gets printed. - * - * Stubs the render function rather than requiring a built checkout, so this covers - * the branch on CI too. + * Boost calls enqueue_scripts() on its own page and depends on the data handle by name. * * @runInSeparateProcess * @preserveGlobalState disabled @@ -367,29 +336,14 @@ public function test_enqueue_scripts_keeps_the_legacy_bundle_when_wp_build_never */ #[RunInSeparateProcess] #[PreserveGlobalState( false )] - public function test_enqueue_scripts_moves_the_state_to_the_data_handle_when_wp_build_loaded() { - $_GET['page'] = 'my-jetpack'; - add_filter( self::FLAG_FILTER, '__return_true' ); - - // Stands in for the generated build/pages/ render function the flag-on path gates on. - require_once __DIR__ . '/stubs/wp-build-render-page.php'; - - wp_register_script( 'wp-jp-i18n-loader', 'https://example.org/i18n.js', array(), '1.0.0', true ); + public function test_enqueue_scripts_prints_only_the_state_on_another_plugins_page() { + $_GET['page'] = 'jetpack-boost'; + $_GET['step'] = 'onboarding'; Initializer::enqueue_scripts(); - $this->assertTrue( wp_script_is( Initializer::DATA_SCRIPT_HANDLE, 'registered' ) ); - $this->assertFalse( wp_script_is( 'my_jetpack_main_app', 'registered' ) ); - - // The esbuild bundles don't depend on the loader, so it needs enqueueing by hand. - $this->assertTrue( wp_script_is( 'wp-jp-i18n-loader', 'enqueued' ) ); - - // wp_localize_script() writes to `data`; Connection_Initial_State uses an inline `before`. - $localized = wp_scripts()->get_data( Initializer::DATA_SCRIPT_HANDLE, 'data' ); - $this->assertStringContainsString( 'myJetpackInitialState', $localized ); - $this->assertStringContainsString( 'myJetpackRest', $localized ); - - $before = implode( '', (array) wp_scripts()->get_data( Initializer::DATA_SCRIPT_HANDLE, 'before' ) ); - $this->assertStringContainsString( 'JP_CONNECTION_INITIAL_STATE', $before ); + $this->assertSame( 'my_jetpack_main_app', Initializer::DATA_SCRIPT_HANDLE ); + $this->assert_state_is_on_the_data_handle(); + $this->assertFalse( wp_script_is( Initializer::ONBOARDING_SCRIPT_HANDLE, 'registered' ) ); } } diff --git a/projects/packages/my-jetpack/tests/php/Register_Wp_Build_Polyfills_Test.php b/projects/packages/my-jetpack/tests/php/Register_Wp_Build_Polyfills_Test.php deleted file mode 100644 index e75d9ca27d1a..000000000000 --- a/projects/packages/my-jetpack/tests/php/Register_Wp_Build_Polyfills_Test.php +++ /dev/null @@ -1,58 +0,0 @@ - array(), - 'hooked' => false, - 'wp_version_threshold' => '7.0', - ) as $name => $value ) { - $prop = new ReflectionProperty( WP_Build_Polyfills::class, $name ); - if ( PHP_VERSION_ID < 80100 ) { - $prop->setAccessible( true ); - } - $prop->setValue( null, $value ); - } - parent::tearDown(); - } - - /** - * Registering requests each required handle for the `my-jetpack` consumer. - */ - public function test_registers_required_polyfill_handles() { - Initializer::register_wp_build_polyfills(); - - $consumers = WP_Build_Polyfills::get_consumers(); - - foreach ( self::EXPECTED_HANDLES as $handle ) { - $this->assertArrayHasKey( $handle, $consumers, "$handle should be requested" ); - $this->assertContains( 'my-jetpack', $consumers[ $handle ], "$handle should list the my-jetpack consumer" ); - } - } -} diff --git a/projects/packages/my-jetpack/tests/php/Script_Data_Test.php b/projects/packages/my-jetpack/tests/php/Script_Data_Test.php index 0078d3c979f9..1639c074cb9d 100644 --- a/projects/packages/my-jetpack/tests/php/Script_Data_Test.php +++ b/projects/packages/my-jetpack/tests/php/Script_Data_Test.php @@ -46,10 +46,8 @@ public function test_adds_the_products_section() { $filter = 'jetpack_feature_flag_enabled_' . Initializer::FEATURES_TAB_FEATURE_FLAG; $this->assertNull( Initializer::add_admin_script_data( array() )['myJetpack']['productsSection'] ); - add_filter( 'jetpack_feature_flag_enabled_' . Initializer::WP_BUILD_FEATURE_FLAG, '__return_true' ); add_filter( $filter, '__return_true' ); $data = Initializer::add_admin_script_data( array() ); - remove_all_filters( 'jetpack_feature_flag_enabled_' . Initializer::WP_BUILD_FEATURE_FLAG ); remove_all_filters( $filter ); $this->assertSame( 'features', $data['myJetpack']['productsSection']['slug'] ); diff --git a/projects/packages/my-jetpack/webpack.config.js b/projects/packages/my-jetpack/webpack.config.js index 50738f322423..f01157a09d41 100644 --- a/projects/packages/my-jetpack/webpack.config.js +++ b/projects/packages/my-jetpack/webpack.config.js @@ -6,7 +6,7 @@ const __dirname = import.meta.dirname; export default [ { entry: { - index: './_inc/admin.jsx', + onboarding: './_inc/onboarding.jsx', 'async-notification-bubble': './_inc/utils/async-notification-bubble.ts', }, mode: jetpackWebpackConfig.mode, diff --git a/projects/plugins/jetpack/tests/php/_inc/lib/Akismet_Admin_Chrome_Test.php b/projects/plugins/jetpack/tests/php/_inc/lib/Akismet_Admin_Chrome_Test.php index 504eb0b4649d..6dd1a3efc2e2 100644 --- a/projects/plugins/jetpack/tests/php/_inc/lib/Akismet_Admin_Chrome_Test.php +++ b/projects/plugins/jetpack/tests/php/_inc/lib/Akismet_Admin_Chrome_Test.php @@ -39,7 +39,6 @@ public function set_up() { * Undo the constant and cached status the individual tests set. */ public function tear_down() { - remove_all_filters( 'jetpack_feature_flag_enabled_my-jetpack-wp-build' ); remove_all_filters( 'jetpack_feature_flag_enabled_my-jetpack-features-tab' ); Constants::clear_single_constant( 'IS_WPCOM' ); Status_Cache::clear(); @@ -158,7 +157,6 @@ public function test_render_footer_hides_the_products_and_help_links_on_wpcom() * With My Jetpack's Features tab on, the footer links to it under its new name. */ public function test_render_footer_links_to_the_features_tab_when_it_replaces_products() { - add_filter( 'jetpack_feature_flag_enabled_my-jetpack-wp-build', '__return_true' ); add_filter( 'jetpack_feature_flag_enabled_my-jetpack-features-tab', '__return_true' ); $footer = $this->render( array( new Akismet_Admin_Chrome(), 'render_footer' ) ); diff --git a/tools/performance/scripts/scenarios.js b/tools/performance/scripts/scenarios.js index 87d10b2e1b67..067e603792d6 100644 --- a/tools/performance/scripts/scenarios.js +++ b/tools/performance/scripts/scenarios.js @@ -176,8 +176,8 @@ export const SCENARIOS = [ defaultUrl: 'http://localhost:8083', header: 'My Jetpack (simulated WP.com connection)', // The My Jetpack admin page - the heaviest Jetpack admin bundle. PHP emits an empty - // `
` (`#my-jetpack-dashboard-wp-admin-app` under the - // modernization flag) and React renders MyJetpackScreen into it, so measure-lcp.js waits for the AdminPage frame (`.jp-admin-page`, a non-hashed + // `
` (`#my-jetpack-dashboard-wp-admin-app` once served + // through wp-build) and React renders MyJetpackScreen into it, so measure-lcp.js waits for the AdminPage frame (`.jp-admin-page`, a non-hashed // class from @automattic/jetpack-components) to appear so a run measures the rendered app, // not the empty shell. Capture completeness then rests on the networkidle wait plus the // stable resource count, not the frame selector (`.jp-admin-page` renders with its children From d105a02c58ed986dc09cda06b37a92996d8ca0c4 Mon Sep 17 00:00:00 2001 From: Douglas Date: Thu, 17 Sep 2026 12:42:51 -0300 Subject: [PATCH 2/2] Changelog Co-Authored-By: Claude Opus 5 (1M context) --- .../changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../backup/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../boost/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../jetpack/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../protect/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../search/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../social/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../stats/changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ .../changelog/update-my-jetpack-retire-wp-build-flag | 4 ++++ 9 files changed, 36 insertions(+) create mode 100644 projects/packages/my-jetpack/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/backup/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/boost/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/jetpack/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/protect/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/search/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/social/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/stats/changelog/update-my-jetpack-retire-wp-build-flag create mode 100644 projects/plugins/videopress/changelog/update-my-jetpack-retire-wp-build-flag diff --git a/projects/packages/my-jetpack/changelog/update-my-jetpack-retire-wp-build-flag b/projects/packages/my-jetpack/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..e575bac78b6e --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Show the dashboard in the new rounded admin page frame on every site. diff --git a/projects/plugins/backup/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/backup/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/backup/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/boost/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/boost/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/boost/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/jetpack/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/jetpack/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..0e492bde1eb9 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/protect/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/protect/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/protect/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/search/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/search/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/search/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/social/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/social/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/social/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/stats/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/stats/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/stats/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame. diff --git a/projects/plugins/videopress/changelog/update-my-jetpack-retire-wp-build-flag b/projects/plugins/videopress/changelog/update-my-jetpack-retire-wp-build-flag new file mode 100644 index 000000000000..f589208d8341 --- /dev/null +++ b/projects/plugins/videopress/changelog/update-my-jetpack-retire-wp-build-flag @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +My Jetpack: Show the dashboard in the new rounded admin page frame.