Hydrogen/Sanity connect chokes on GraphQL query with products, fixed in latest plugin version

21 replies
Last updated: Apr 26, 2022
spun up my own very simple example of hydrogen/sanity connect and when trying to query my home page with some modules + products it suddenly chokes, and very specifically if a module has products in it:
Cannot destructure property 'data' of '__vite_ssr_import_3__.useSkippableShopQuery(...)' as it is undefined.
TypeError: Cannot destructure property 'data' of '__vite_ssr_import_3__.useSkippableShopQuery(...)' as it is undefined.
    at Module.useSanityShopifyProducts [as default] (/node_modules/hydrogen-plugin-sanity/dist/useSanityShopifyProducts.js:57:19)
    at Module.useSanityQuery (/node_modules/hydrogen-plugin-sanity/dist/useSanityQuery.js:59:58)
AI Update

This error is happening because the hydrogen-plugin-sanity package has been deprecated and is no longer compatible with current versions of Hydrogen. The package was officially deprecated in April 2023, and the GitHub repository shows it's now archived and read-only.

The core issue is that useSkippableShopQuery (which was part of older Hydrogen versions) has changed or been removed in newer Hydrogen releases. The deprecated plugin is trying to call it internally within useSanityShopifyProducts, but it's returning undefined, which causes the destructuring error you're seeing.

The Solution

Stop using hydrogen-plugin-sanity entirely. The Sanity team deprecated it because it promoted patterns that worked against React Server Components' benefits - specifically, it encouraged large page-level fetches and shared context that made code harder to reason about.

Instead, use the official @sanity/client library directly with Hydrogen's native useQuery hook:

// MyServerComponent.server.jsx
import sanityClient from '@sanity/client'
import {useQuery} from '@shopify/hydrogen'

const query = `*[_type == 'page' && slug.current == $slug]`
const params = {slug: 'about'}

// Configure Sanity client
const client = sanityClient({
  apiVersion: 'v2022-05-01',
  dataset: 'your-dataset',
  projectId: 'your-project-id',
  useCdn: true
})

export default function MyServerComponent() {
  const {data, error} = useQuery([query, params], async () => {
    return await client.fetch(query, params)
  })
  
  return <div>{JSON.stringify(data)}</div>
}

Handling Products with Modules

For your specific case where modules contain products, you'll need to:

  1. Fetch your Sanity content (modules and their product references) using @sanity/client
  2. Extract the Shopify product IDs from your Sanity data
  3. Fetch those products separately using Hydrogen's Storefront API within the components that need them

This approach gives you much better control over:

  • Caching strategies per component
  • Prefetching logic for better performance
  • Component boundaries that work well with React Server Components

The deprecated plugin tried to automatically fetch all referenced Shopify products for you in one go, but this created issues with component isolation and made it harder to optimize performance. By keeping fetching logic scoped to specific components (even when deeply nested in modules), you'll have more predictable behavior and better performance characteristics.

removing the products all it is fetched just fine
is this… a grapqQL issue?
Thanks for reporting
user G
- we’ll look into it. I know some things have changed recently in Hydrogen that might cause this.
it’s been pretty smooth sailing otherwise though, hydrogen sites are absolutely in my future
We look for products and then forward a chunked request to the graphql endpoints in Shopify to get updated inventory. So it's never stale.
Do give word if you've got requests for the sync app!
mmm it’s possible I’m out dated
let me try and update hydrogen
I think we might be behind actually - lmk how it goes
so y’all are also hitting shopify with your product request then
We are - to make sure that you're not getting anything that's not been updated. Do you think it's makes sense?
i guess because this is server rendered that’s a nice bonus
i usually double dip that because i’m used to static rendering everything
We’ll be doing more work on this so appreciate any feedback
I'm playing with y'all's package directly but a lil out of my depths, will PR it if I fix it on my side
Will let you know when we find time to pick this up
It was on 0.13 but it's happening in the latest too. I haven't actually tried to render data into a pdp yet, just a reference on the home page
Thanks! We’ll be bringing in upstream changes into both the demo and plugin real shortly (it was last stable around
~0.11
and there’s been a bunch of breaking changes since).
user G
this is now fixed in
0.4.0
of the plugin and should work in all currently known versions of Hydrogen
>= 0.13.0

(There was a breaking change introduced in Hydrogen
0.13.0
)
luckily this is a test site i am making for my gf, the stability of hydrogen seems not there lol

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?