Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
westonruter opened this issue Apr 15, 2024 · 0 comments · Fixed by #1143
Closed
Labels
[Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) [Type] Bug An existing feature is broken

Comments

@westonruter
Copy link
Member

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).

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) labels Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant