Skip to content

Conversation

@mikejolley
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

wc-cart-fragments allows statically rendered elements to be updated when a product is added to the cart. It does this with an additional AJAX call to the get_refreshed_fragments endpoint. This does create a performance issue where extra requests are made to the server to support it.

There are several articles on the web detailing how this is a problem and recommending to dequeue it [1], as well as workarounds which replace the functionality entirely [2].

Given that the main consumer of this functionality is the Cart Widget, and that the Cart Widget is being superseded by the Mini Cart Block, I propose we remove this from the global enqueues and move it to the Cart Widget only, so the widget can continue to use fragments, but other pages in the store do not need to load the script.

This was proposed here: woocommerce/woocommerce-blocks#7168

We plan on removing support for fragments in WooCommerce Blocks, and potentially dequeuing it completely in the interim.

How to test the changes in this Pull Request:

  1. With the patch applied, and with no widgets setup, visit the shop page.
  2. View the page source and confirm the cart-fragments.js script is not loaded.
  3. Add the cart widget to a sidebar in the theme.
  4. View the page source and confirm the cart-fragments.js script is loaded.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Nov 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

Test Results Summary

Commit SHA: 32bd197

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests26700202690m 54s
E2E Tests1890010019918m 30s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@samueljseay samueljseay added Cart Issues related to the cart. needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. labels May 4, 2023
@samueljseay samueljseay requested review from a team and Konamiman and removed request for a team May 4, 2023 07:48
@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

Hi @Konamiman,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@Konamiman Konamiman self-requested a review May 18, 2023 08:11
@mikejolley
Copy link
Member Author

mikejolley commented May 19, 2023

Ill go ahead and merge this before the feature freeze. The following note can be included with the release:

The Cart Fragments script, responsible for updating the cart widget after a successful add to cart event, can cause a performance issue on stores not making use of that functionality. To mitigate this, the script will now only be enqueued if using the Mini Cart widget.

Stores with similar functionality (e.g. from a theme) that are not using the widget can re-enable this functionality by either adding the widget to one of their widget areas/sidebars, or by enqueuing the script manually:

wp_enqueue_script( 'wc-cart-fragments' );

If you're looking for an alternative to the Mini Cart widget that does not suffer from the performance issue, try the Mini Cart Block instead.

@MehbubRashid
Copy link

Isn't it a breaking change? In my theme the code $(document.body).trigger('wc_fragment_refresh') is used in some places. After updating WooCommerce, I am noticing few features are not working in the frontend and at last i found the reason to be this change. Good for me that I noticed it. Other users who have the same code related to wc_fragment_refresh, they wont even know that the old features of their site is not working after updating WooCommerce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cart Issues related to the cart. needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants