Skip to content

Conversation

samandeepbishnoi
Copy link

Problem

When running the project locally with Shopify as the provider, a server-side exception crashes the app during layout rendering

Root cause:

  • shopifyFetch() throws a non-standard object (throw {}), which cannot be caught by try/catch or error boundaries in React.
  • getCart() does not handle failed fetches or missing cart data.
  • SHOPIFY_GRAPHQL_API_ENDPOINT was used as a relative path, which breaks SSR fetch requests if environment variables are not configured properly.

✅ What This PR Fixes

  • Wraps getCart() logic in a try/catch block to prevent layout crashes.
  • Replaces throw {} in shopifyFetch() with standard Error instances for compatibility with error boundaries.
  • Adds detailed logging for easier debugging of Shopify GraphQL errors and fetch failures.
  • Ensures endpoint is constructed correctly using the full store domain and versioned API path.
  • Updates .env.example to include SHOPIFY_STOREFRONT_API_VERSION.

🧪 Verification

  • npm run dev works with correct .env.local setup
  • ✅ Page loads even if no cart cookie exists
  • ✅ API errors from Shopify are logged but no longer crash the app
  • ✅ Cart gracefully falls back to undefined if invalid or missing

⚠️ Developer Note

Make sure your .env.local file is correctly set up with valid credentials and fully qualified Shopify domain

Copy link

vercel bot commented Jul 7, 2025

Someone is attempting to deploy a commit to the Vercel Solutions Team on Vercel.

A member of the Team first needs to authorize it.

@samandeepbishnoi
Copy link
Author

Hi team 👋,

This is my first open-source contribution — I fixed a Shopify layout crash caused by unhandled API errors and misconfigured endpoint logic. The PR ensures proper error handling in shopifyFetch, wraps getCart() in try/catch, and fixes environment-based endpoint generation.

Would love a review or feedback — happy to make changes! 🙌

Thanks for maintaining this amazing project 🚀

@samandeepbishnoi
Copy link
Author

samandeepbishnoi commented Jul 8, 2025

Thank you for the detailed review! 🙏
I've made the requested changes:

Removed package-lock.json as the repo uses pnpm.

Updated .env.example with SHOPIFY_STOREFRONT_API_VERSION=2025-07 as per latest docs.

Fixed the extra tabbing headers in shopifyFetch().

@brienna
Copy link

brienna commented Jul 22, 2025

+1 this helped fix my problem

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.

5 participants