The selected variant should reach the cart.
Change a size or color. The original handler keeps the first SKU; the patched handler reads the selection at the moment you add.
Constructed technical demonstration. This is an intentionally introduced bug in a local model. It is not a customer result, a live store, or a production WooCommerce or Shopify integration.
Try the same action in both modes
Choose White / L, then add to each cart. The expected SKU is DEMO-WHT-L.
Original handler
Intentional stale-selection bug
Sample overshirt
Last add action
- Selected at click
No item added- Added to cart
No item added
Choose a variant and add it.
Inspect cart (0 items)
The cart is empty.
Patched handler
Current selection read when adding
Sample overshirt
Last add action
- Selected at click
No item added- Added to cart
No item added
Choose a variant and add it.
Inspect cart (0 items)
The cart is empty.
Each cart is independent. Changing a selection after an add does not alter the earlier cart line. Refreshing the page clears both carts.
Run the regression checks
Seven explicit SKU checks execute against fresh instances of both handlers. Your demonstration carts are not changed.
Checks have not run in this browser.
| Contract check | Expected cart SKU(s) | Original actual | Patched actual |
|---|
A failure in the original handler demonstrates the defect. Passing these local checks does not validate a third-party store, browser compatibility, inventory, payment processing, or revenue.
Inspect the change
Captured at initialization
const capturedVariant = initialVariant;
function addToCart() {
return addLine(capturedVariant);
}Read at action time
function addToCart() {
return addLine(selectedVariant);
}These snippets isolate the change. The complete source below includes selection validation, independent cart state, and isolated snapshots.
Run the dependency-free test suite from this folder:
node --test cart.test.mjs