-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] ShopifyProvider throws an error when used in remix #1718
Comments
Thank you for reporting this! The problem with #1 is that when running in Hydrogen, if the prop is provided, we still need to put that on the request because that is how other server components get at the data (server components don't have real context at the moment). |
Yeah there is still a lot to be done to remove the framework-specific parts out of components, to make them agnostic. @elisenyang can give more details about the timeline of when we will start working on this effort again. |
The same issue happens when trying to run on Next.js. Using hooks such as |
Thanks, @matheusgrieger, we’re aware — the components and hooks are not decoupled from the framework yet, but it's something we’ve been working on. We’ve been first focused on built a single great end-to-end experience for our 1.0 launch—but we’re fans of both Remix & Next and will be bringing most of our providers, hooks, components, and utilities to both of them soon. We’re looking at supporting other frameworks in the future as well. |
For folks interested in side-stepping the RSC/SSR aspects of ShopifyProvider, here's a workaround if you're comfortable with tweaking webpack (Nextjs, Gatsby) or overriding esbuild (Remix) 🔧
This should allow for basic foundation usage of Providers, Cart hooks etc. Gatsby implementation in the wild : projectn95 |
We now have a version of |
Describe the bug
We're using hydrogen inside remix, with the goal of using most/all hydrogen functionality except for
useShopQuery
(following similar logic to this discussion). Since many hooks such asuseCart
require aShopifyProvider
, we intend to wrap most of our app in aShopifyProvider
in our remixroot.tsx
.The issue is that
ShopifyProvider
callsuseServerRequest
, which then tries touseContext(RequestContextSSR)
, which fails withReferenceError: __HYDROGEN_TEST__ is not defined
from this line. This path isn't necessary for us anyway, since we're making all our server-side calls in a remixloader
, we just needShopifyProviderClient
(which sets upShopifyContext
).Workarounds we've tried or considered on our side:
ShopifyProviderClient
instead ofShopifyProvider
. Two issues: it's not exported (as far as we can tell), and since the file is namedShopifyProvider.client.js
, remix won't include it in the server bundle (this one took a while to figure out 😅).ShopifyContext
from here and set it ourselves. This does work 🎉, except it's not exported outside of hydrogen, and feels a little hacky.ServerRequestProvider
to try to getuseServerRequest
to pass without error. We didn't test this method, since it's not exported either and seems the same as option 2 but harder.Two ideas to fix it in hydrogen:
ShopifyProvider
to not calluseServerRequest
if ashopifyConfig
prop is passed. This looks pretty straightforward at first glance, changing here and here.ShopifyProviderClient
and guide people to use that directly in remix/next.To Reproduce
Minimal reproduction: https://github.com/wintersieck/remix-hydrogen-issue. It's just
npx create-remix
, version bumped to React 18, with hydrogen installed and added toroot.tsx
.Expected behaviour
Be able to use
ShopifyProvider
in a remix app, or a similar path to set up context for client-side components and hooks to work.Screenshots
Additional context
The text was updated successfully, but these errors were encountered: