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

Refresh fragments infinite loop with multisite #10940

Closed
seriusokhatsky opened this issue May 18, 2016 · 8 comments
Closed

Refresh fragments infinite loop with multisite #10940

seriusokhatsky opened this issue May 18, 2016 · 8 comments
Assignees
Labels
type: bug The issue is a confirmed bug.

Comments

@seriusokhatsky
Copy link

EXPLANATION OF THE ISSUE

When I have a few stores created as a multisite with woocommerce installed, after adding product to cart AJAX request is initiated (wc-ajax=get_refreshed_fragments). If I have another tab opened (using google chrome) with the other store (from my multisite) another request starts inside this tab. So if I have two or more tabs with different stores opened in google chrome these requests are calling infinetely. I have tested with Storfront theme too. You can check how it works on this theme on themeforest (it has multisite). Just open two versions in different tabs and inspect it's requests after adding something to cart.
http://woodstock.temashdesign.com/electronics/
http://woodstock.temashdesign.com/watch/

Here is a screenshots of how it looks like
https://gyazo.com/1a6e53416603bd0a1b60359a363bec71

I guess it is because of this part of code
// Refresh when storage changes in another tab $( window ).on( 'storage onstorage', function ( e ) { if ( 'wc_cart_hash' === e.originalEvent.key && localStorage.getItem( 'wc_cart_hash' ) !== sessionStorage.getItem( 'wc_cart_hash' ) ) { $.ajax( $fragment_refresh ); } });

Because cart hashs are not equal between these two multisite.

Please give me some respond about this, maybe I do something wrong? If it is really a plugin issue I can try to prepare PR to fix this.

STEPS TO REPRODUCE THE ISSUE

  1. Create a multisite store
  2. Open two sites in different tabs
  3. Add something to cart
  4. Inspect AJAX requests

SYSTEM STATUS REPORT

`
### WordPress Environment ###

WC Version: 2.5.5
Log Directory Writable: ✔
WP Version: 4.5.2
WP Multisite: ✔
WP Memory Limit: 256 MB
WP Debug Mode: ✔
Language: en_US

### Server Environment ###

Server Info: Apache
PHP Version: 5.5.35
PHP Post Max Size: 800 MB
PHP Time Limit: 3000
PHP Max Input Vars: 5000
SUHOSIN Installed: –
MySQL Version: 5.5.49
Max Upload Size: 17 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

### Database ###

WC Database Version: 2.5.5
: 
woocommerce_sessions: ✔
woocommerce_api_keys: ✔
woocommerce_attribute_taxonomies: ✔
woocommerce_termmeta: ✔
woocommerce_downloadable_product_permissions: ✔
woocommerce_order_items: ✔
woocommerce_order_itemmeta: ✔
woocommerce_tax_rates: ✔
woocommerce_tax_rate_locations: ✔

### Active Plugins (18) ###

Menu Management Enhancer (WebStyle.Me - All For WebMasters...): by Chris Mavricos
SevenSpark – 1.1

Contact Form 7: by Takayuki Miyoshi – 4.4.2
Cookie Notice: by dFactory – 1.2.35
Plugin for showcase of elements: by Serg – 1.0.0
WPBakery Visual Composer: by Michael M - WPBakery.com – 4.11.2
Kraken Image Optimizer: by Karim Salman – 2.5.1
MailChimp for WordPress Lite: by ibericode – 2.3.15
Monster Widget: by Automattic – 0.3
Open Swatch - Woocommerce Color Swatch: by anhvnit@gmail.com – 1.0
Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 2.2.6
Slider Revolution: by ThemePunch – 5.2.5.1
Woocommerce Monster Widget: by Alispx – 1.0.2
WooCommerce: by WooThemes – 2.5.5
WordPress Importer: by wordpressdotorg – 0.6.1
YITH WooCommerce Wishlist: by YITHEMES – 2.0.15
Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 2.2.6
Transients Manager: by Pippin Williamson – 1.7.2
Yoast SEO: by Team Yoast – 3.2.5
W3 Total Cache: by Frederick Townes – 0.9.4.1
Widget Importer & Exporter: by Steven Gliebe – 1.2.4
SrcSet Responsive Images for Wordpress: by Benjamin Moody
Eric Holmes – 1.4

Menu Exporter: by Joe Hoyle - Human Made Limited – 1

### Settings ###

Force SSL: –
Currency: GBP (£)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2

### API ###

API Enabled: ✔
API Version: 3.1.0

### WC Pages ###

Shop Base: #4 - /shop/
Cart: #5 - /cart/
Checkout: #6 - /checkout/
My Account: #7 - /my-account/

### Taxonomies ###

Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)


### Theme ###

Name: Storefront
Version: 1.6.1 – 2.0.1 is available
Author URL: http://www.woothemes.com
Child Theme: ✕ – If you're modifying WooCommerce on a parent theme you didn't build personally
then we recommend using a child theme. See: How to create a child theme

WooCommerce Support: ✔

### Templates ###

Overrides: –
`
@mikejolley
Copy link
Member

Is WC activated per site or across the network...

@seriusokhatsky
Copy link
Author

@mikejolley in both cases

@mikejolley
Copy link
Member

There is a doc about this somewhere but I cannot find it. I think you need a unique cookie per site. Possibly related https://tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop/

@seriusokhatsky
Copy link
Author

It doesn't help, is it not plugin related?

Maybe you need to add some blog id value to the cart hash?

if ( 'wc_cart_hash' === e.originalEvent.key && localStorage.getItem( 'wc_cart_hash' ) !== sessionStorage.getItem( 'wc_cart_hash' ) ) {
$.ajax( $fragment_refresh );
}

@DavidAnderson684
Copy link
Contributor

I see infinite loops for this same fragment too, but on ordinary single site installs. I've seen it several times whilst testing extensions I'm working on. I've not managed to get it down to a list of reproducible steps. It seems to be in core - a few days ago, I de-activated all other extensions, and it still happened. It's somehow related to multiple tabs open. I tweaked that bit of JavaScript to log to the console both localStorage.getItem( 'wc_cart_hash' ) and sessionStorage.getItem( 'wc_cart_hash' ) - and it was logging the same values for each of them endlessly (i.e. neither value changed to become equal to the other).

@mikejolley
Copy link
Member

mikejolley commented May 20, 2016

@coderkevin I wonder if this is one you maybe want to look into? The code in question is in cart-fragments.js:

// Refresh when storage changes in another tab
        $( window ).on( 'storage onstorage', function ( e ) {
            if ( 'wc_cart_hash' === e.originalEvent.key && localStorage.getItem( 'wc_cart_hash' ) !== sessionStorage.getItem( 'wc_cart_hash' ) ) {
                $.ajax( $fragment_refresh );
            }
        });

This is supposed to update the cart widgets if you add to cart in another tab. I guess this needs some form of protection against infinite loops if one tab updates and then triggers another etc etc

@mikejolley mikejolley added the type: bug The issue is a confirmed bug. label May 20, 2016
@coderkevin coderkevin self-assigned this May 21, 2016
@coderkevin
Copy link
Contributor

I started looking into this today and got a multi-site test environment set up on this on our master branch. I have reproduced the issue in my test environment and will look at solving it tomorrow. Thanks!

@coderkevin
Copy link
Contributor

This is fixed in PR #10983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

4 participants