Skip to content

Conversation

@odanree
Copy link
Owner

@odanree odanree commented Nov 13, 2025

Problem

E2E tests were failing with React error #423: 'too many re-renders'. Root cause was CartContext accessing localStorage during server-side rendering, causing hydration mismatch.

Solution

  1. CartContext Hydration Fix

    • Added \isMounted\ state flag to track client-side mount
    • Wrapped localStorage access with \ ypeof window !== 'undefined'\ checks
    • Only save cart to localStorage after component mounts (\isMounted && typeof window)
    • Prevents SSR/client mismatch that triggers React hydration errors
  2. Re-enable E2E Workflow

    • Restored \pull_request\ and \push\ triggers on dev/main branches
    • Tests should now pass with proper SSR handling in CartContext

Changes

  • \shopify-headless/contexts/CartContext.tsx: Add SSR hydration safety
  • .github/workflows/cypress.yml: Re-enable pull_request/push triggers

Testing

Tests will run on this PR to verify:

  • No React hydration errors
  • All E2E test suites pass
  • Cart functionality preserved

Impact

  • Restores E2E test coverage to CI/CD pipeline
  • Fixes React error #423 that blocks all test runs
  • Maintains cart persistence with proper SSR handling

- Add isMounted flag to prevent localStorage access during SSR
- Check typeof window to ensure client-side only execution
- Prevents hydration mismatch that caused React error #423
- Fixes E2E test failures by ensuring proper client/server boundaries
- E2E tests disabled due to React error #423 (hydration mismatch)
- CartContext now properly guards localStorage access for SSR
- Re-enable pull_request and push triggers on dev/main branches
- Tests should now pass with isMounted flag preventing SSR localStorage conflicts
@vercel
Copy link

vercel bot commented Nov 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
shopify-headless Ignored Ignored Nov 13, 2025 8:14am

@odanree odanree merged commit 7765597 into main Nov 13, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants