TGC

Cart items disappear on refresh

TGC

Cart items disappear on refresh

Cart items disappear on refresh

Cart items should persist across page refreshes. If they're disappearing, here's how to fix it.

How cart persistence works

TGC stores cart data in localStorage. When you refresh or navigate:

  1. Page loads

  2. TGC runtime initialises

  3. Cart state is restored from localStorage

  4. Components display the saved cart

Common causes

1. Private/incognito browsing

Private browsing modes often block or clear localStorage.

Fix: Test in a normal browser window. This is expected behaviour in private mode.

2. Browser blocking localStorage

Some browsers or extensions block storage.


Check:

  1. Open browser dev tools (F12)

  2. Go to Console

  3. Look for errors about "localStorage" or "storage"

Fix:

  • Disable storage-blocking extensions

  • Check browser privacy settings

  • Try a different browser

3. TGC runtime not initialising

If the runtime doesn't load, the cart can't restore.

Check:

  1. Open browser dev tools (F12)

  2. In Console, type: window.__tgc

  3. If it returns undefined, the runtime isn't loading

Fix:

  • Make sure you have at least one TGC component on the page

  • Check for JavaScript errors in the console

  • Republish your site

4. Multiple domains or subdomains

localStorage is scoped to the domain. Cart data on www.mysite.com won't appear on mysite.com.

Fix:

  • Use consistent domain (with or without www)

  • Set up redirects to your preferred domain

5. Credentials not injected

Without credentials, the runtime partially fails.

Fix:

  1. Open TGC plugin

  2. Verify you're connected

  3. Republish your site

Debugging steps

  1. Add item to cart

  2. Open dev tools → Application tab → Local Storage

  3. Find your site's domain

  4. Look for a key like tgc_cart

  5. Refresh the page

  6. Check if the tgc_cart key is still there

If the key disappears on refresh, something is clearing storage.

Testing cart persistence

  1. Open your live site

  2. Add 2-3 items to cart

  3. Open cart drawer — verify items are there

  4. Refresh the page

  5. Open cart drawer again — items should still be there

  6. Navigate to a different page

  7. Open cart drawer — items should still be there