Debugging and testing Hydrogen apps
Any web app can run into issues, and Hydrogen apps are no exception. This guide shows you how to debug and troubleshoot your Hydrogen app for common issues.
Debugging tools
Anchor link to section titled "Debugging tools"Hydrogen includes several tools to help you debug your project, both when developing locally and in production.
Common errors
Anchor link to section titled "Common errors"These are some issues developers often run into when building with Hydrogen, and how to investigate or fix them:
Slow API queries
Anchor link to section titled "Slow API queries"Sub-optimal API queries can make sites feel slow. Large or complex queries can delay API response times, and too many synchronous requests can lead to a waterfall effect that blocks rendering. To start addressing these issues:
- Use Hydrogen's Subrequest profiler to isolate and eliminate bloat.
- Learn about caching Shopify API data with Hydrogen.
Unoptimized caching strategies
Anchor link to section titled "Unoptimized caching strategies"By default, Hydrogen caches all queries to the Storefront API. However, it's likely you can cache certain parts of your app for longer than the default time period. To fine-tune your caching:
- Learn about caching Shopify API data with Hydrogen.
- Consider when you could use full-page caching.
- Use the Subrequest profiler to check cache hits and misses.
Slow or heavy dependencies
Anchor link to section titled "Slow or heavy dependencies"Certain dependencies can increase your compiled app bundle size, contributing to slower start times and sluggish performance. Analyze your dependency graph to find the offending packages:
- Use the bundle size analyzer to find large dependencies.
- Attach a debugger to identify bottlenecks in server-side code.
Failing Oxygen deployments
Anchor link to section titled "Failing Oxygen deployments"Deploying to Oxygen could fail for several reasons. Some common ways to diagnose these errors:
- In the Shopify admin, check the deployment logs on the deployment detail page.
- Check that you're not using Node.js APIs that aren't available in Oxygen's Worker-based runtime.
- Check that you're not exceeding Oxygen's file size limits. Try compressing files, or using a third-party CDN for required assets that exceed Oxygen limits.
- Profile your CPU startup time to find processes that might be timing out.
- Inspect your bundle size to remove unecessary or bloated dependencies.
React hydration errors
Anchor link to section titled "React hydration errors"React hydration errors in the browser console indicate that the HTML rendered on the server doesn't match the HTML that React found on the browser when adding interactivity with JavaScript. This can happen for multiple reasons and is likely specific to your code, so there's no single solution that can fix the problem. Generally, you can try to comment out or remove part of your code to isolate the issue and find the root cause.
A common cause of hydration mismatch in React and Remix apps is that a browser extension modifies the HTML of the page before React uses it. You can check if this is the case in your app by opening incognito mode or private browsing without browser extensions. Refer to this issue for more information.
End-to-end testing
Anchor link to section titled "End-to-end testing"You can add end-to-end testing of your Hydrogen deployments with authentication bypass tokens. These tokens allow third-party CI/CD platforms to securely access your deployments for testing purposes.