Skip to content

Hydrogen SDK: Troubleshooting

Beta SDK

These SDKs are currently in beta. APIs may change before stable release.

Common issues and solutions when using @rebuy/hydrogen-sdk.

Debug Mode

Enable debug logging to troubleshoot issues.

Server-Side Logging

Set the environment variable:

# .env
REBUY_SDK_DEBUG=true

This will output detailed logs to your server console when using getRebuyData in loaders.

Client-Side Logging

In the browser console:

window.REBUY_SDK_DEBUG = true;

This enables logging for client-side components like RecentlyViewed.

What Debug Mode Shows

  • API requests and responses
  • Context object being sent to Rebuy
  • Cart data transformation
  • Error details with stack traces

Common Issues

TypeScript Context Type Issue

If you encounter type errors with the context parameter in getRebuyData:

Type 'AppLoadContext' is not assignable to type 'RebuyLoadContext'

You may need to cast the context:

const { rebuy } = await getRebuyData({
    context: context as any, // Temporary workaround for type differences
    request,
});

Note

This is a known issue that will be addressed in a future version.

Products Not Updating When Cart Changes

If recommendations don't update after cart changes, ensure:

  1. You're using getRebuyData in your loader (not a client component)
  2. The cart mutation is using Hydrogen's <CartForm>
  3. You're passing the request parameter to getRebuyData
// Correct
export async function loader({ context, request }: LoaderFunctionArgs) {
    const { rebuy } = await getRebuyData({ context, request }); // ← request is required
    // ...
}

Recently Viewed Not Showing Products

The RecentlyViewed component requires:

  1. RebuyProvider is wrapping your app
  2. RebuyProductView is on your product pages to track views
  3. The user has viewed at least one product

Check that RebuyProductView is correctly set up:

<RebuyProductView
    product={{
        id: product.id,      // Must be Shopify GraphQL ID
        handle: product.handle,
    }}
/>

API Key Not Found

If you see "API key not found" errors:

  1. Verify your .env file has the correct variable:

    PUBLIC_REBUY_API_KEY=your-api-key
    

  2. Restart your development server after adding environment variables

  3. For production, ensure environment variables are configured in your hosting platform

Empty Recommendations

If API calls succeed but return empty arrays:

  1. Check the Data Source ID exists in your Rebuy Admin
  2. Verify products exist and are published in your Shopify store
  3. Check if "Filter Input Products" is removing all products
  4. Try with a simpler API call first:
    const products = await rebuy.sdk.products.getTopSellers({ limit: 5 });
    console.log('Products:', products);
    

CSP (Content Security Policy) Errors

If you see CSP errors related to inline scripts, add the nonce prop to RebuyProvider:

<RebuyProvider
    apiKey={process.env.PUBLIC_REBUY_API_KEY}
    nonce={yourNonceValue}
>

Getting Help

If you're still experiencing issues:

  1. Enable debug mode and check the console output
  2. Verify your API key is correct
  3. Test with a simple API call to isolate the problem
  4. Check the SDK version matches the documentation
See something that needs updating? Suggest an edit