-
Notifications
You must be signed in to change notification settings - Fork 107
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
Investigate offloading woocommerce-google-analytics-integration to a worker in Web Worker Offloading #1741
Comments
It seems the root cause of this issue lies in how the A key issue here is that WooCommerce Core uses jQuery's $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); jQuery's When the (credit to @b1ink0 for helping figure this out) This limitation appears to be specific to Classic themes. Block themes handle these interactions differently (code ref), which might explain why the issue doesn't occur there. Potential WorkaroundA possible workaround involves creating a "stub" or "proxy" function in the main thread that bridges the gap between the main thread and the Web Worker. The idea is to capture the Here's a proof-of-concept (still hacky): add_action(
'wp_footer',
static function (): void {
?>
<script>
// Main thread: Define a proxy handler for added_to_cart events in the main thread.
document.body.onadded_to_cart = function(...args) {
const customEvent = new CustomEvent('wwo_wc_added_to_cart', {
detail: args,
});
document.dispatchEvent(customEvent);
};
</script>
<script type="text/partytown">
// Web Worker: Listen for the proxied event in the worker and trigger the real handler.
document.addEventListener('wwo_wc_added_to_cart', (event) => {
if (document.body.onadded_to_cart) {
// Call the original handler with the passed arguments
document.body.onadded_to_cart(...event.detail);
}
});
</script>
<?php
}
); This workaround leverages the native Initial testing shows that this approach restores functionality for wwo-wc.mp4 |
Great investigation! Nevertheless, unless there is a demonstrated performance value for moving |
The
woocommerce-google-analytics-integration
script had to be removed from being offloaded to a worker in #1740 due to events likeadd_to_cart
not being sent. We should investigate further why this wasn't working and potentially re-offload that script to the worker.The text was updated successfully, but these errors were encountered: