Commit 671ef798658 for woocommerce

commit 671ef7986582c50f33761054f64b5231f4bc3b68
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Thu May 21 09:09:40 2026 +0200

    Fix products dashboard URL query handling (#65217)

    * Fix products dashboard query parameter handling

    * Add changelog for products dashboard URL fix

diff --git a/packages/js/experimental-products-app/changelog/fix-products-dashboard-undefined-url b/packages/js/experimental-products-app/changelog/fix-products-dashboard-undefined-url
new file mode 100644
index 00000000000..62de213387b
--- /dev/null
+++ b/packages/js/experimental-products-app/changelog/fix-products-dashboard-undefined-url
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent product dashboard interactions from adding an invalid undefined query parameter to the URL.
diff --git a/packages/js/experimental-products-app/src/app.tsx b/packages/js/experimental-products-app/src/app.tsx
index 508109b24bd..b15753a307d 100644
--- a/packages/js/experimental-products-app/src/app.tsx
+++ b/packages/js/experimental-products-app/src/app.tsx
@@ -35,7 +35,7 @@ export function ProductsApp() {
 	return (
 		<NewNavigationProvider>
 			<UnsavedChangesWarning />
-			<RouterProvider>
+			<RouterProvider pathArg="page">
 				<ThemeProvider isRoot>
 					<ProductsLayout />
 				</ThemeProvider>
diff --git a/packages/js/experimental-products-app/src/product-list/utils.test.ts b/packages/js/experimental-products-app/src/product-list/utils.test.ts
index 76720a55445..0e209dccadb 100644
--- a/packages/js/experimental-products-app/src/product-list/utils.test.ts
+++ b/packages/js/experimental-products-app/src/product-list/utils.test.ts
@@ -2,7 +2,10 @@
  * Internal dependencies
  */
 import type { ProductEntityRecord } from '../fields/types';
-import { getProductsWithEmbeddedVariations } from './utils';
+import {
+	getProductListNavigationPath,
+	getProductsWithEmbeddedVariations,
+} from './utils';

 function createProduct(
 	id: number,
@@ -17,6 +20,35 @@ function createProduct(
 }

 describe( 'product list utils', () => {
+	describe( 'getProductListNavigationPath', () => {
+		it( 'preserves existing query args when adding new params', () => {
+			expect(
+				getProductListNavigationPath(
+					'woocommerce-products-dashboard?post_type=product',
+					{
+						activeView: 'draft',
+					}
+				)
+			).toBe(
+				'woocommerce-products-dashboard?post_type=product&activeView=draft'
+			);
+		} );
+
+		it( 'removes invalid undefined params from the existing query and new params', () => {
+			expect(
+				getProductListNavigationPath(
+					'woocommerce-products-dashboard?undefined=%2F&post_type=product',
+					{
+						undefined: '/',
+						activeView: 'draft',
+					}
+				)
+			).toBe(
+				'woocommerce-products-dashboard?post_type=product&activeView=draft'
+			);
+		} );
+	} );
+
 	describe( 'getProductsWithEmbeddedVariations', () => {
 		it( 'adds embedded variations after their parent product', () => {
 			const variation = createProduct( 2, 1 );
diff --git a/packages/js/experimental-products-app/src/product-list/utils.ts b/packages/js/experimental-products-app/src/product-list/utils.ts
index ad88eba0743..d88c76906ec 100644
--- a/packages/js/experimental-products-app/src/product-list/utils.ts
+++ b/packages/js/experimental-products-app/src/product-list/utils.ts
@@ -1,7 +1,7 @@
 /**
  * External dependencies
  */
-import { addQueryArgs } from '@wordpress/url';
+import { addQueryArgs, getQueryArgs } from '@wordpress/url';

 /**
  * Internal dependencies
@@ -11,11 +11,21 @@ import { PRODUCT_LIST_TAB_VALUES, type StatusTab } from './constants';

 export function getProductListNavigationPath(
 	path: string,
-	params: Record< string, string >
+	params: Record< string, string | undefined >
 ) {
 	const [ pathname = '/' ] = path.split( '?' );
-
-	return addQueryArgs( pathname, params );
+	const query = {
+		...getQueryArgs( path ),
+		...params,
+	};
+	const sanitizedQuery = Object.fromEntries(
+		Object.entries( query ).filter(
+			( [ key, value ] ) =>
+				key !== 'undefined' && typeof value !== 'undefined'
+		)
+	);
+
+	return addQueryArgs( pathname, sanitizedQuery );
 }

 export function getItemId( item: ProductEntityRecord ) {