Commit 7497b8ec888 for woocommerce

commit 7497b8ec888e30079960142061abc824e2efbbf7
Author: Tom Cafferkey <tjcafferkey@gmail.com>
Date:   Mon Nov 30 11:38:08 2026 +0000

    Fix setup wizard getting stuck after browser Back (#70922)

    * Fix setup wizard getting stuck after browser Back

    * Add changelog entry for setup wizard browser navigation

diff --git a/plugins/woocommerce/changelog/fix-core-profiler-browser-back b/plugins/woocommerce/changelog/fix-core-profiler-browser-back
new file mode 100644
index 00000000000..02d7195f8c9
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-core-profiler-browser-back
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Restore setup forms instead of stuck loading screens when using the browser Back button after store setup.
diff --git a/plugins/woocommerce/client/admin/client/core-profiler/index.tsx b/plugins/woocommerce/client/admin/client/core-profiler/index.tsx
index bd21e0d3371..bcd4d082441 100644
--- a/plugins/woocommerce/client/admin/client/core-profiler/index.tsx
+++ b/plugins/woocommerce/client/admin/client/core-profiler/index.tsx
@@ -647,9 +647,17 @@ const browserPopstateHandler = fromCallback( ( { sendBack } ) => {
 	const popstateHandler = () => {
 		sendBack( { type: 'EXTERNAL_URL_UPDATE' } );
 	};
+	const pageshowHandler = ( event: PageTransitionEvent ) => {
+		// A cached page can restore a completed loader instead of the step in the URL.
+		if ( event.persisted ) {
+			popstateHandler();
+		}
+	};
 	window.addEventListener( 'popstate', popstateHandler );
+	window.addEventListener( 'pageshow', pageshowHandler );
 	return () => {
 		window.removeEventListener( 'popstate', popstateHandler );
+		window.removeEventListener( 'pageshow', pageshowHandler );
 	};
 } );

@@ -1551,15 +1559,17 @@ export const coreProfilerStateMachineDefinition = createMachine( {
 									}: {
 										event: DoneActorEvent< Extension[] >;
 									} ) => {
-										// Skip the plugins page
-										// When there is 0 plugin returned from the server
-										// Or all the plugins are activated already.
+										// Keep explicit navigation to this step available after installation.
+										const { step } = getQuery() as {
+											step?: string;
+										};
 										return (
 											event.output.length === 0 ||
-											event.output.every(
-												( plugin: Extension ) =>
-													plugin.is_activated
-											)
+											( step !== 'plugins' &&
+												event.output.every(
+													( plugin: Extension ) =>
+														plugin.is_activated
+												) )
 										);
 									},
 								},
diff --git a/plugins/woocommerce/client/admin/client/core-profiler/services/installAndActivatePlugins.ts b/plugins/woocommerce/client/admin/client/core-profiler/services/installAndActivatePlugins.ts
index d945bc3b826..bc66b615496 100644
--- a/plugins/woocommerce/client/admin/client/core-profiler/services/installAndActivatePlugins.ts
+++ b/plugins/woocommerce/client/admin/client/core-profiler/services/installAndActivatePlugins.ts
@@ -137,8 +137,17 @@ export const pluginInstallerMachine = createMachine(
 				},
 				states: {
 					installer: {
-						initial: 'installing',
+						initial: 'checkQueue',
 						states: {
+							checkQueue: {
+								always: [
+									{
+										target: 'installing',
+										guard: 'hasPluginsToInstall',
+									},
+									{ target: '#installation-finished' },
+								],
+							},
 							installing: {
 								invoke: {
 									systemId: 'installPlugin',
diff --git a/plugins/woocommerce/client/admin/client/core-profiler/services/test/installAndActivatePlugins.test.ts b/plugins/woocommerce/client/admin/client/core-profiler/services/test/installAndActivatePlugins.test.ts
index ad6675cf97b..78fbec0f4cf 100644
--- a/plugins/woocommerce/client/admin/client/core-profiler/services/test/installAndActivatePlugins.test.ts
+++ b/plugins/woocommerce/client/admin/client/core-profiler/services/test/installAndActivatePlugins.test.ts
@@ -27,6 +27,28 @@ describe( 'pluginInstallerMachine', () => {
 		jest.resetAllMocks();
 	} );

+	it( 'reports success immediately without installing when the selection is empty', () => {
+		const installPlugin = jest.fn();
+		const service = createActor(
+			pluginInstallerMachine.provide( {
+				...mockConfig,
+				actors: { installPlugin: fromPromise( installPlugin ) },
+			} ),
+			{ input: { selectedPlugins: [], pluginsAvailable: [] } }
+		).start();
+
+		expect( service.getSnapshot().matches( 'reportSuccess' ) ).toBe( true );
+		expect( service.getSnapshot().context.installedPlugins ).toEqual( [] );
+		expect( installPlugin ).not.toHaveBeenCalled();
+		expect(
+			mockConfig.actions.updateParentWithInstallationSuccess
+		).toHaveBeenCalledTimes( 1 );
+		expect(
+			mockConfig.actions.updateParentWithPluginProgress
+		).not.toHaveBeenCalled();
+		service.stop();
+	} );
+
 	it.each< [ string, string, number, number ] >( [
 		[ 'woocommerce-services:tax', 'woocommerce-services', 4000, 4000 ],
 		[ 'woocommerce-services', 'woocommerce-services', 4000, 4000 ],