Commit 3ad42ba3bfc for woocommerce

commit 3ad42ba3bfc380e6798df9bbbdbae6b1cef3b827
Author: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com>
Date:   Tue Dec 1 16:19:26 2026 +0100

    Hold the store notices context on the Add to Cart + Options form instead of a wrapper div (#71364)

    * Render Add to Cart + Options notices inside its form

    The form now holds the store notices context next to its own, so the
    block no longer wraps the form in an element whose only job is to hold
    that context. The notices list is the form's first child and uses the
    shared notices renderer, whose dismiss button does not submit the form.

    The block's own notices renderer is deprecated.

    * Cover Add to Cart + Options notices end to end

    Check that validation, cart, and Add to wishlist errors appear inside
    the block with their role and styling, that a second invalid submit does
    not duplicate them, and that dismissing one does not submit the form.

    * Check notices stay in their block when a page has several

    * Check the Add to Cart + Options block follows its column's flow layout

    * Restore libxml error handling after the notices render test

    * Reset the first inner block's margin while no notice is shown

    The hidden notices list is the form's first child, so the flow layout's
    first-child margin reset skipped the first inner block, whose margin then
    collapsed through the form and added space above the block.

    * Describe the Add to Cart + Options change as merchants see it

    * Add the block library changelog entry for the Add to Cart + Options change

    * Check that the page shows the notice only once

    The Store Notices block prints only server-side notices, so checking its
    text could never catch a notice raised on the client. Count the notices
    on the whole page instead.

    * Check that the notices list declares no context of its own

    A context on the list would hide the form's store notices context from
    the notices it renders.

    * Deprecate the block's notices renderer in 11.5.0

    * Use product type constants in the notices render test

    * Wait for each notice submit to be handled before checking it

    A second invalid submit replaces the notice only after the store notices
    module loads, so wait for the new notice before counting. Check that
    dismissing a notice fires no submit event instead of counting notices.

    * Measure the block's flow layout against its parent and own margins

    Compare the block's width with its parent's content width, and the space
    to each sibling with their collapsed margins, so the check holds in any
    flow layout and when a sibling is missing.

    * Hide the block's notices list while it has no notices

    The shared notices styles set `display: block`, which overrides the
    list's `hidden` attribute. In themes whose flow layout sets no margins,
    the empty list's bottom margin then showed as space above the block.

    * Wait for the page's JavaScript and check spacing in the two-block test

    An Add to cart click before the JavaScript is ready submits the form
    natively, and the server's notice then shows in the Store Notices block
    as a second alert. Selecting an option only works once the JavaScript is
    ready, so the test does that first and then clicks once.

    The test also checks that the first block takes the Single Product
    block's width and adds no space above itself.

    * Remove the block's old notices renderer

    The block renders its notices list inside the form, so its own renderer,
    which wrapped the form, has no caller left.

    * Test the notices render structure for simple and grouped products

    * Group the hidden notices list rules and name the themes they serve

    * Drop the check that dismissing a notice fires no submit

    A mouse click on the dismiss button can't submit the form even without
    `type="button"`, so the check could never fail. The PHP render test
    guards the attribute.

    * Reduce the template layout step to width and first-block margin checks

    The two-block test checks the space around the block inside a Single
    Product block.

    * Note that the block can adopt supports.layout

    * Hide empty notices lists in the shared notices styles

    The shared `display: block` overrode the `hidden` attribute, so an empty
    notices list stayed in the layout with its margins. Hiding it there
    covers Add to Cart + Options, Wishlist and Saved for Later, so the block
    keeps only its first-inner-block margin reset.

    ---------

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/tweak-add-to-cart-with-options-notices-in-form b/plugins/woocommerce/changelog/tweak-add-to-cart-with-options-notices-in-form
new file mode 100644
index 00000000000..106024f2e78
--- /dev/null
+++ b/plugins/woocommerce/changelog/tweak-add-to-cart-with-options-notices-in-form
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Show the Add to Cart + Options block at the same width and spacing as the blocks around it.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/style.scss b/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/style.scss
index d7dc5751f50..1648e2b900f 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/style.scss
@@ -11,6 +11,12 @@
 	display: none;
 }

+// The notices list is the form's first child, so the flow layout's first-child
+// margin reset doesn't reach the first inner block. Reset it while no notice is shown.
+.wc-block-add-to-cart-with-options__notices[hidden] + * {
+	margin-block-start: 0;
+}
+
 // Set the height to 100% so when the quantity selector is inside a flex
 // container with `verticalAlignment: stretch` (that's the default in WC core
 // templates), the quantity selector will stretch to the height of the container.
diff --git a/plugins/woocommerce/client/blocks/changelog/tweak-add-to-cart-with-options-notices-in-form b/plugins/woocommerce/client/blocks/changelog/tweak-add-to-cart-with-options-notices-in-form
new file mode 100644
index 00000000000..106024f2e78
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/changelog/tweak-add-to-cart-with-options-notices-in-form
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Show the Add to Cart + Options block at the same width and spacing as the blocks around it.
diff --git a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/store-notices-container/style.scss b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/store-notices-container/style.scss
index 4c7812f6de2..db3ec9954a0 100644
--- a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/store-notices-container/style.scss
+++ b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/store-notices-container/style.scss
@@ -1,6 +1,9 @@
 .wc-block-components-notices {
 	display: block;
 	margin: 1.5em 0;
+	&[hidden] {
+		display: none;
+	}
 	&:first-child {
 		margin-top: 0;
 	}
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 949ff9ba529..123a7faa965 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -46513,12 +46513,6 @@ parameters:
 			count: 1
 			path: src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php

-		-
-			message: '#^Method Automattic\\WooCommerce\\Blocks\\BlockTypes\\AddToCartWithOptions\\AddToCartWithOptions\:\:render_interactivity_notices_region\(\) should return string but returns string\|false\.$#'
-			identifier: return.type
-			count: 1
-			path: src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
-
 		-
 			message: '#^Offset ''class'' on array\{class\: string, style\: mixed, data\-wp\-interactive\: ''woocommerce/add\-to…'', data\-wp\-class\-\-is\-invalid\: ''\!state\.isFormValid''\} in isset\(\) always exists and is not nullable\.$#'
 			identifier: isset.offset
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
index f7a9d11ba7f..3cfe6634ccb 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartWithOptions/AddToCartWithOptions.php
@@ -10,6 +10,7 @@ use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
 use Automattic\WooCommerce\Blocks\Utils\Utils as BlocksUtils;
 use Automattic\WooCommerce\Enums\ProductType;
 use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
+use Automattic\WooCommerce\Internal\ShopperLists\ShopperListRenderer;
 use Automattic\WooCommerce\Internal\ShopperLists\ShopperListsController;

 /**
@@ -551,6 +552,7 @@ class AddToCartWithOptions extends AbstractBlock {

 			$cart_redirect_after_add = get_option( 'woocommerce_cart_redirect_after_add' );
 			$form_attributes         = '';
+			$notices_region          = '';
 			$legacy_mode             = 'yes' === $cart_redirect_after_add || $this->has_form_elements( $hooks_before ) || $this->has_form_elements( $hooks_after );
 			if ( $legacy_mode ) {
 				$action_url   = BlocksUtils::get_current_page_url();
@@ -580,10 +582,14 @@ class AddToCartWithOptions extends AbstractBlock {
 					'class'   => $form_classes,
 				);
 			} else {
-				// Otherwise, we use the Interactivity API.
+				// Otherwise, we use the Interactivity API. The form also holds the
+				// store notices context, so notices raised by the form and the
+				// blocks inside it are listed at the top of the form.
 				$form_attributes = array(
-					'data-wp-on--submit' => 'actions.addToCart',
+					'data-wp-on--submit'        => 'actions.addToCart',
+					'data-wp-context---notices' => 'woocommerce/store-notices::' . (string) wp_json_encode( array( 'notices' => array() ) ),
 				);
+				$notices_region  = ShopperListRenderer::render_interactivity_notices_region( 'wc-block-add-to-cart-with-options__notices' );
 			}

 			// These hidden inputs are used by extensions or Express Payment methods to gather information of the form state.
@@ -604,7 +610,7 @@ class AddToCartWithOptions extends AbstractBlock {
 			}

 			$form_html = sprintf(
-				'<form %1$s %2$s>%3$s%4$s%5$s%6$s</form>',
+				'<form %1$s %2$s>%3$s%4$s%5$s%6$s%7$s</form>',
 				get_block_wrapper_attributes(
 					array_merge(
 						$wrapper_attributes,
@@ -619,11 +625,8 @@ class AddToCartWithOptions extends AbstractBlock {
 										// Add the `is-layout-flow` class so inner elements automatically get the
 										// default vertical margin from the theme. That's especially useful for
 										// elements added by extensions like express payment method buttons.
-										// In the future, we want to use `supports.layout` in block.json instead
-										// of hardcoding the class here. However, right now that wouldn't work
-										// because the wrapper element of the block is the notices `<div>`, so the
-										// `is-layout-flow` class would be applied to the notices container instead
-										// of the `<form>` as we want.
+										// phpcs:ignore Generic.Commenting.Todo.TaskFound
+										// @todo Now that the form is the block wrapper, use `supports.layout` in block.json instead.
 										'is-layout-flow',
 									)
 								)
@@ -632,6 +635,7 @@ class AddToCartWithOptions extends AbstractBlock {
 					)
 				),
 				$context_directive,
+				$notices_region,
 				$hooks_before,
 				$template_part_blocks,
 				$hooks_after,
@@ -655,10 +659,6 @@ class AddToCartWithOptions extends AbstractBlock {
 			}

 			$form_html = $form_html . ob_get_clean();
-
-			if ( ! $legacy_mode ) {
-				$form_html = $this->render_interactivity_notices_region( $form_html );
-			}
 		} else {
 			ob_start();

@@ -696,52 +696,4 @@ class AddToCartWithOptions extends AbstractBlock {

 		return $form_html;
 	}
-
-	/**
-	 * Render interactivity API powered notices that can be added client-side. This reuses classes
-	 * from the woocommerce/store-notices block to ensure style consistency.
-	 *
-	 * @param string $form_html The form HTML.
-	 * @return string The rendered store notices HTML.
-	 */
-	protected function render_interactivity_notices_region( $form_html ) {
-		$context_directive = wp_interactivity_data_wp_context(
-			array(
-				'notices' => array(),
-			)
-		);
-
-		ob_start();
-		?>
-		<div data-wp-interactive="woocommerce/store-notices" class="wc-block-components-notices alignwide" <?php echo $context_directive; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
-			<template data-wp-each--notice="context.notices" data-wp-each-key="context.notice.id">
-				<div
-					class="wc-block-components-notice-banner"
-					data-wp-class--is-error="state.isError"
-					data-wp-class--is-success="state.isSuccess"
-					data-wp-class--is-info="state.isInfo"
-					data-wp-class--is-dismissible="context.notice.dismissible"
-					data-wp-bind--role="state.role"
-					data-wp-watch="callbacks.injectIcon"
-				>
-					<div class="wc-block-components-notice-banner__content">
-						<span data-wp-init="callbacks.renderNoticeContent" aria-live="assertive" aria-atomic="true"></span>
-					</div>
-					<button
-						data-wp-bind--hidden="!context.notice.dismissible"
-						class="wc-block-components-button wp-element-button wc-block-components-notice-banner__dismiss contained"
-						aria-label="<?php esc_attr_e( 'Dismiss this notice', 'woocommerce' ); ?>"
-						data-wp-on--click="actions.removeNotice"
-					>
-						<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
-							<path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z" />
-						</svg>
-					</button>
-				</div>
-			</template>
-			<?php echo $form_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
-		</div>
-		<?php
-		return ob_get_clean();
-	}
 }
diff --git a/plugins/woocommerce/src/Internal/ShopperLists/ShopperListRenderer.php b/plugins/woocommerce/src/Internal/ShopperLists/ShopperListRenderer.php
index a41a6549afa..81048681a69 100644
--- a/plugins/woocommerce/src/Internal/ShopperLists/ShopperListRenderer.php
+++ b/plugins/woocommerce/src/Internal/ShopperLists/ShopperListRenderer.php
@@ -224,9 +224,9 @@ final class ShopperListRenderer {
 	}

 	/**
-	 * Render the iAPI store-notices region used by the row-level error
-	 * banners. Mirrors `AddToCartWithOptions::render_interactivity_notices_region()`
-	 * — keep in sync if the shape changes.
+	 * Render the iAPI store-notices list shared by the blocks that keep their
+	 * notices in a `woocommerce/store-notices` context on their own wrapper
+	 * (shopper lists, Add to Cart + Options). The list declares no context.
 	 *
 	 * @param string $wrapper_class Class attribute for the outer `<div>`.
 	 * @return string
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
index b971ec9ce44..89e474bb4a5 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
@@ -243,14 +243,74 @@ test.describe( 'Add to Cart + Options Block', () => {
 						.locator( '.wp-block-accordion-panel' )
 				: page.getByLabel( 'Additional Information', { exact: true } );

+		await test.step( 'takes the width of its column, with no margin above its first inner block', async () => {
+			const { width, columnContentWidth } = await page
+				.locator(
+					'[data-block-name="woocommerce/add-to-cart-with-options"]'
+				)
+				.evaluate( ( block ) => {
+					const px = ( element: Element, property: string ) =>
+						parseFloat(
+							getComputedStyle( element ).getPropertyValue(
+								property
+							)
+						);
+					const column = block.parentElement as Element;
+					return {
+						width: block.getBoundingClientRect().width,
+						columnContentWidth:
+							column.getBoundingClientRect().width -
+							px( column, 'padding-inline-start' ) -
+							px( column, 'padding-inline-end' ) -
+							px( column, 'border-inline-start-width' ) -
+							px( column, 'border-inline-end-width' ),
+					};
+				} );
+
+			expect( width ).toBeCloseTo( columnContentWidth );
+
+			// The first inner block gets no flow margin while no notice is shown.
+			await expect(
+				addToCartBlock.locator(
+					'.wp-block-woocommerce-add-to-cart-with-options-variation-selector'
+				)
+			).toHaveCSS( 'margin-block-start', '0px' );
+		} );
+
 		await test.step( 'displays an error when attributes are not selected', async () => {
 			await addToCartButton.click();

+			const notice = addToCartBlock.getByRole( 'alert' );
+			await expect( notice ).toHaveText(
+				'Please select product attributes before adding to cart.'
+			);
+			await expect( notice ).toHaveClass( /\bis-error\b/ );
+			await expect( notice.locator( 'svg' ).first() ).toBeVisible();
+
+			const noticeBox = await notice.boundingBox();
+			const colorBox = await addToCartBlock
+				.getByRole( 'radiogroup', { name: 'Color' } )
+				.boundingBox();
+			expect( noticeBox?.y ).toBeLessThan( colorBox?.y ?? 0 );
+
+			// Submitting the invalid form again replaces the notice instead of
+			// adding a second one. The replacement is a new element, so wait
+			// for it before counting.
+			await notice.evaluate( ( element ) =>
+				element.setAttribute( 'data-test-first-submit', '' )
+			);
+			await addToCartButton.click();
 			await expect(
-				page.getByText(
-					'Please select product attributes before adding to cart.'
+				addToCartBlock.locator(
+					'[role="alert"]:not([data-test-first-submit])'
 				)
-			).toBeVisible();
+			).toHaveCount( 1 );
+			await expect( notice ).toHaveCount( 1 );
+
+			await notice
+				.getByRole( 'button', { name: 'Dismiss this notice' } )
+				.click();
+			await expect( notice ).toHaveCount( 0 );
 		} );

 		await test.step( 'updates blocks rendering variation data when attributes are selected', async () => {
@@ -529,6 +589,9 @@ test.describe( 'Add to Cart + Options Block', () => {

 		await page.goto( '/product/logo-collection' );

+		const addToCartBlock = page.locator(
+			'[data-block-name="woocommerce/add-to-cart-with-options"]'
+		);
 		const addToCartButton = page
 			.getByRole( 'button', { name: 'Add to cart' } )
 			.first();
@@ -540,11 +603,9 @@ test.describe( 'Add to Cart + Options Block', () => {
 			// stores have been loaded.
 			await expect( async () => {
 				await addToCartButton.click();
-				await expect(
-					page.getByText(
-						'Please select some products to add to the cart.'
-					)
-				).toBeVisible();
+				await expect( addToCartBlock.getByRole( 'alert' ) ).toHaveText(
+					'Please select some products to add to the cart.'
+				);
 			} ).toPass();
 		} );

@@ -677,9 +738,11 @@ test.describe( 'Add to Cart + Options Block', () => {
 			).toBeVisible();
 			// Verify error message is displayed.
 			await expect(
-				page.getByText(
-					'The quantity of "Hoodie with Logo" cannot be changed'
-				)
+				addToCartBlock
+					.getByRole( 'alert' )
+					.getByText(
+						'The quantity of "Hoodie with Logo" cannot be changed'
+					)
 			).toBeVisible();
 			// Verify optimistic updates were applied, so the product that was
 			// successfully added to cart is counted.
@@ -1254,6 +1317,140 @@ test.describe( 'Add to Cart + Options Block', () => {
 		).toHaveValue( '1' );
 	} );

+	test( 'shows notices only in the block that raised them when a page has several', async ( {
+		page,
+		requestUtils,
+	} ) => {
+		const productIds = [];
+		for ( const slug of [ 'hoodie', 'v-neck-t-shirt' ] ) {
+			const cliOutput = await wpCLI(
+				`post list --post_type=product --field=ID --name="${ slug }" --format=ids`
+			);
+			productIds.push( cliOutput.stdout.match( /\d+/g )?.pop() );
+		}
+		// The first block follows a paragraph, to measure the space above it.
+		const singleProductBlocks = productIds
+			.map(
+				( productId, index ) =>
+					`<!-- wp:woocommerce/single-product {"productId":${ productId }} --><div class="wp-block-woocommerce-single-product woocommerce">${
+						index === 0
+							? '<!-- wp:paragraph --><p>Before the block.</p><!-- /wp:paragraph --><!-- wp:woocommerce/add-to-cart-with-options /-->'
+							: '<!-- wp:woocommerce/add-to-cart-with-options /-->'
+					}</div><!-- /wp:woocommerce/single-product -->`
+			)
+			.join( '' );
+		const testPage = await requestUtils.rest< { link: string } >( {
+			method: 'POST',
+			path: '/wp/v2/pages',
+			data: {
+				status: 'publish',
+				title: 'Two Add to Cart + Options blocks',
+				content: `<!-- wp:woocommerce/store-notices /-->${ singleProductBlocks }`,
+			},
+		} );
+
+		await page.goto( testPage.link );
+
+		const addToCartBlocks = page.locator(
+			'[data-block-name="woocommerce/add-to-cart-with-options"]'
+		);
+		const firstBlock = addToCartBlocks.nth( 0 );
+
+		await test.step( 'takes the width of the Single Product block and adds no space above itself', async () => {
+			const layout = await firstBlock.evaluate( ( block ) => {
+				const px = ( element: Element, property: string ) =>
+					parseFloat(
+						getComputedStyle( element ).getPropertyValue( property )
+					);
+				const box = block.getBoundingClientRect();
+				const parent = block.parentElement as Element;
+				const previous = block.previousElementSibling as Element;
+				return {
+					width: box.width,
+					parentContentWidth:
+						parent.getBoundingClientRect().width -
+						px( parent, 'padding-inline-start' ) -
+						px( parent, 'padding-inline-end' ) -
+						px( parent, 'border-inline-start-width' ) -
+						px( parent, 'border-inline-end-width' ),
+					gapAbove: box.top - previous.getBoundingClientRect().bottom,
+					previousMargin: px( previous, 'margin-block-end' ),
+				};
+			} );
+
+			expect( layout.width ).toBeCloseTo( layout.parentContentWidth );
+			expect( layout.gapAbove ).toBeCloseTo( layout.previousMargin );
+		} );
+
+		// Before its JavaScript is ready, an Add to cart click submits the
+		// form natively and reloads the page. Selecting an option only works
+		// once the JavaScript is ready, so wait for that first.
+		const colorBlueOption = firstBlock
+			.getByRole( 'radiogroup', { name: 'Color' } )
+			.getByRole( 'radio', { name: 'Blue', exact: true } );
+		await expect( async () => {
+			await colorBlueOption.click();
+			await expect( colorBlueOption ).toBeChecked( { timeout: 1_000 } );
+		} ).toPass();
+
+		await firstBlock
+			.getByRole( 'button', { name: 'Add to cart', exact: true } )
+			.click();
+		await expect( firstBlock.getByRole( 'alert' ) ).toHaveText(
+			'Please select product attributes before adding to cart.'
+		);
+
+		// The notice shows once on the whole page: not in the second block,
+		// nor in the page-level Store Notices block.
+		await expect( page.getByRole( 'alert' ) ).toHaveCount( 1 );
+	} );
+
+	test( 'shows Add to wishlist errors inside the block', async ( {
+		page,
+		pageObject,
+		editor,
+	} ) => {
+		await wpCLI( 'option set woocommerce_product_wishlist_enabled yes' );
+
+		await pageObject.updateSingleProductTemplate();
+
+		await editor.saveSiteEditorEntities( {
+			isOnlyCurrentEntityDirty: true,
+		} );
+
+		const errorMessage = 'The product could not be saved to your wishlist.';
+		await page.route( /shopper-lists/, ( route ) =>
+			route.request().method() === 'POST'
+				? route.fulfill( {
+						status: 500,
+						json: {
+							code: 'woocommerce_rest_wishlist_error',
+							message: errorMessage,
+							data: { status: 500 },
+						},
+					} )
+				: route.continue()
+		);
+
+		await page.goto( '/product/beanie/' );
+
+		const addToCartBlock = page.locator(
+			'[data-block-name="woocommerce/add-to-cart-with-options"]'
+		);
+
+		// There is the chance the button might be clicked before the iAPI
+		// stores have been loaded.
+		await expect( async () => {
+			await addToCartBlock
+				.getByRole( 'button', { name: 'Add to wishlist' } )
+				.click();
+			await expect( addToCartBlock.getByRole( 'alert' ) ).toHaveText(
+				errorMessage,
+				{ timeout: 1_000 }
+			);
+		} ).toPass();
+	} );
+
 	test.describe( 'autoselect behavior', () => {
 		const productSlug = 'autoselect-t-shirt';
 		const productName = 'Autoselect T-shirt';
diff --git a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php
index a67859b7dbc..725343351da 100644
--- a/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php
+++ b/plugins/woocommerce/tests/php/src/Blocks/BlockTypes/AddToCartWithOptions.php
@@ -5,6 +5,7 @@ declare( strict_types = 1 );
 namespace Automattic\WooCommerce\Tests\Blocks\BlockTypes;

 use Automattic\WooCommerce\Enums\ProductStockStatus;
+use Automattic\WooCommerce\Enums\ProductType;
 use Automattic\WooCommerce\Tests\Blocks\Utils\WC_Product_Custom;
 use Automattic\WooCommerce\Tests\Blocks\Helpers\BlockTypeRegistryTrait;
 use Automattic\WooCommerce\Tests\Blocks\Helpers\FixtureData;
@@ -237,6 +238,7 @@ class AddToCartWithOptions extends \WC_Unit_Test_Case {

 		$this->assertStringContainsString( 'action="https://example.com"', $markup, 'The form has an action that redirects to the page defined by the woocommerce_add_to_cart_form_action filter.' );
 		$this->assertStringNotContainsString( 'data-wp-on--submit', $markup, 'The form doesn\'t have an on submit event when redirect after add is enabled.' );
+		$this->assertStringNotContainsString( 'woocommerce/store-notices', $markup, 'The HTML form has no store notices context or notices list.' );

 		// Test when cart redirect is disabled.
 		update_option( 'woocommerce_cart_redirect_after_add', 'no' );
@@ -265,6 +267,67 @@ class AddToCartWithOptions extends \WC_Unit_Test_Case {
 		$this->assertStringContainsString( 'data-wp-on--submit', $markup, 'The form has an on submit event when an extension hooks into the form but not adding a form element.' );
 	}

+	/**
+	 * @testdox The interactive form holds the store notices context and its notices list, with no element enclosing it for a $product_type product.
+	 *
+	 * @dataProvider provider_interactive_product_types
+	 *
+	 * @param string $product_type Product type under test.
+	 */
+	public function test_interactive_form_holds_store_notices_context( string $product_type ): void {
+		global $product;
+
+		$previous_product = $product;
+		$product          = ProductType::GROUPED === $product_type
+			? \WC_Helper_Product::create_grouped_product()
+			: \WC_Helper_Product::create_simple_product();
+
+		try {
+			$markup = do_blocks( '<!-- wp:woocommerce/single-product {"productId":' . $product->get_id() . '} --><div class="wp-block-woocommerce-single-product woocommerce"><!-- wp:woocommerce/add-to-cart-with-options /--></div><!-- /wp:woocommerce/single-product -->' );
+		} finally {
+			$product = $previous_product;
+		}
+
+		$dom                  = new \DOMDocument();
+		$previous_libxml_mode = libxml_use_internal_errors( true );
+		$dom->loadHTML( '<?xml encoding="utf-8"?>' . $markup );
+		libxml_clear_errors();
+		libxml_use_internal_errors( $previous_libxml_mode );
+		$xpath = new \DOMXPath( $dom );
+
+		$form = $xpath->query( '//form[contains(concat(" ", @class, " "), " wc-block-add-to-cart-with-options ")]' )->item( 0 );
+		$this->assertInstanceOf( \DOMElement::class, $form, 'The block renders its form.' );
+
+		$this->assertSame( 0, $xpath->query( 'ancestor::*[@data-wp-interactive="woocommerce/store-notices"]', $form )->length, 'No element encloses the form to provide the store notices context.' );
+
+		$this->assertTrue( $form->hasAttribute( 'data-wp-context' ), 'The form keeps its own context.' );
+		$this->assertSame( 'woocommerce/store-notices::{"notices":[]}', $form->getAttribute( 'data-wp-context---notices' ), 'The form carries an empty store notices context.' );
+
+		$notices_list = $xpath->query( '*', $form )->item( 0 );
+		$this->assertInstanceOf( \DOMElement::class, $notices_list, 'The form has child elements.' );
+		$this->assertSame( 'woocommerce/store-notices', $notices_list->getAttribute( 'data-wp-interactive' ), 'The notices list is the first child of the form.' );
+		$this->assertStringContainsString( 'wc-block-components-notices', $notices_list->getAttribute( 'class' ), 'The notices list uses the store notices styles.' );
+		foreach ( $notices_list->attributes as $attribute ) {
+			$this->assertStringStartsNotWith( 'data-wp-context', $attribute->name, 'The notices list reads the form\'s store notices context instead of declaring its own.' );
+		}
+
+		$dismiss_button = $xpath->query( './/button[@data-wp-on--click="actions.removeNotice"]', $notices_list )->item( 0 );
+		$this->assertInstanceOf( \DOMElement::class, $dismiss_button, 'Each notice has a dismiss button.' );
+		$this->assertSame( 'button', $dismiss_button->getAttribute( 'type' ), 'The dismiss button does not submit the form.' );
+	}
+
+	/**
+	 * Data provider for the product types rendered with the interactive form.
+	 *
+	 * @return array<string, array{string}>
+	 */
+	public static function provider_interactive_product_types(): array {
+		return array(
+			'simple product'  => array( ProductType::SIMPLE ),
+			'grouped product' => array( ProductType::GROUPED ),
+		);
+	}
+
 	/**
 	 * @testdox Legacy add-to-cart forms expose the request fields required by each product type.
 	 *