hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

[BUG] Cache strategies not available to client components

Open beppek opened this issue 3 years ago • 1 comments

Describe the bug The fetchSync hook allows you to set a cache strategy and according to the docs this should be one of the defined cache strategies or a custom one. However, when you try to import the cache strategy in a client component, you get the following error: SyntaxError: The requested module '/node_modules/@shopify/hydrogen/dist/esnext/client.js?v=25d58708' does not provide an export named 'CacheNone'

To Reproduce

Example is in FetchExample.client.jsx.

Expected behaviour Since the docs link to the cache strategies you'd expect to be able to use those, both client and server-side.

Additional context

  • Hydrogen version: Stackblitz: 1.1.0, Local: 1.0.2
  • Node version: Stackblitz: v16.14.2, Local: v17.7.2

beppek avatar Jul 14 '22 03:07 beppek

As this document(https://shopify.dev/api/hydrogen/hooks/global/fetchsync#fetchsync-in-client-components) says, to use fetchSync in client.jsx if you want to set no-store, i think you can just write it like this:

 const data = fetchSync('/api/bestSellers', {
    cache: 'no-store',
  }).json();

await-ovo avatar Jul 14 '22 16:07 await-ovo

We detected some changes in packages/*/package.json or packages/*/src, and there are no updates in the .changeset. If the changes are user-facing and should cause a version bump, run npm run changeset add to track your changes and include them in the next release CHANGELOG. If you are making simple updates to examples or documentation, you do not need to add a changeset.

github-actions[bot] avatar Mar 12 '24 19:03 github-actions[bot]

Oxygen deployed a preview of your hl-pass-language-to-caapi branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
vite ✅ Successful (Logs) Preview deployment Inspect deployment March 13, 2024 6:34 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment March 13, 2024 6:34 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment March 13, 2024 6:34 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment March 13, 2024 6:34 PM
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment March 13, 2024 6:34 PM
skeleton ✅ Successful (Logs) Preview deployment Inspect deployment March 13, 2024 6:34 PM

Learn more about Hydrogen's GitHub integration.

shopify[bot] avatar Mar 12 '24 19:03 shopify[bot]