Skip to content

WooCommerce "Remove from cart" links are prefetched/preloaded in Speculative Loading #1141

@westonruter

Description

@westonruter

Bug Description

WooCommerce has a mini-cart that appears in the header. It has an ✖️ button (actually a link) to remove an item from the cart. Unfortunately Speculative Loading's speculation rules are preloading/prefetching the URL, resulting in the product being removed unexpectedly:

Screen.recording.2024-04-15.12.54.28.webm

Steps to reproduce

  1. Configure WooCommerce with sample data
  2. Enable Speculative Loading
  3. Add a product to the cart (cf. Products added to cart in WooCommerce without clicking on Add to Cart button when Speculative Loading active #1140)
  4. Then click on the mini cart in the header and try hovering over the remove-from-cart button

Additional Context

Here is the source code for the remove-from-cart button: https://github.com/woocommerce/woocommerce/blob/a8e84d8c8b20558f66ed33dcbee6c1dec300752f/plugins/woocommerce/templates/cart/mini-cart.php#L46-L60

The wc_get_cart_remove_url() function, importantly, returns a URL that includes a _wpnonce (added via wp_nonce_url()). An example remove-from-cart link:

https://example.com/cart/?remove_item=1ff1de774005f8da13f42943881c655f&_wpnonce=cb065f29b3

The speculation rules used for the plugin should exclude URLs with _wpnonce by default. This was previously brought up in #733 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Speculative LoadingIssues for the Speculative Loading plugin (formerly Speculation Rules)[Type] BugAn existing feature is broken

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions