Releases: Shopify/hydrogen-v1
v0.11.0-experimental.1
This is an important release that brings us closer to release candidate. Please read the migration guide carefully, as there are a number of breaking changes. You can also use this pull request to view the changes between a brand new app in version 0.10.1 and version 0.11.0.
Breaking changes
shopify.config.js
Hydrogen now implements the 2022-01 version of the Storefront API. Update your shopify.config.js
file to use the 2022-01
storefrontApiVersion
instead of unstable
.
<ShopifyProvider>
Our 0.10 release removed <ShopifyProvider>
. This was necessary because React Server Components do not currently support Context. That change also meant that you could only have a single Shopify configuration for your app. The config was global. After making this change, we received feedback, internally and externally, that there is value in being able to dynamically define the configuration per request. This is useful to aggregate multiple storefronts with a single Hydrogen app.
Because of these requests, we are bringing <ShopifyProvider>
back. The challenge is that context is still not supported in React Server Components. Because of this, the new <ShopifyProvider>
is special with a few shortcomings:
- You cannot have multiple instances of
<ShopifyProvider>
within your app. Because it is not using real context, all<ShopifyProvider>
instances share the same configuration per request. - You are still able to dynamically define the
shopifyConfig
prop, and it will remain isolated per request to the server, being thread safe.
Again, you cannot yet use context within your server components. We are working with Meta and hope to have a long term server context solution soon.
Migrate from Hydrogen version 0.10.0
- Remove
shopifyConfig
from bothentry-client.jsx
andentry-server.jsx
. - Add
ShopifyProvider
andshopifyConfig
toApp.server.jsx
:
import {DefaultRoutes} from '@shopify/hydrogen';
import {Suspense} from 'react';
+ import shopifyConfig from '../shopify.config';
import DefaultSeo from './components/DefaultSeo.server';
import NotFound from './components/NotFound.server';
import AppClient from './App.client';
import LoadingFallback from './components/LoadingFallback';
import {ShopifyProvider} from '@shopify/hydrogen';
export default function App({log, pages, ...serverState}) {
return (
<Suspense fallback={<LoadingFallback />}>
+ <ShopifyProvider shopifyConfig={shopifyConfig}>
<AppClient helmetContext={serverState.helmetContext}>
<DefaultSeo />
<DefaultRoutes
pages={pages}
serverState={serverState}
log={log}
fallback={<NotFound />}
/>
</AppClient>
+ </ShopifyProvider>
</Suspense>
);
}
React Router is completely gone
In version 0.10, we removed React Router on the server. With this release, we have removed React Router on the client as well. In most scenarios this shouldn't be a breaking change, unless you directly use React Router hooks or components within your client components. Simply remove react-router-dom
from your package.json dependencies. Hydrogen exposes the following utilities for routing:
In a later release, we'll continue to enhance the routing capabilities in Hydrogen. Read more in the Custom Routes RFC.
Renamed Model3D
to ModelViewer
The <Model3D />
component has now been renamed to <ModelViewer />
.
Standalone Cart hooks removed
The following Cart hooks were removed because the same functionality can be obtained through the useCart
hook:
useCartAttributesUpdateCallback
useCartBuyerIdentityUpdateCallback
useCartCheckoutUrl
useCartCreateCallback
useCartDiscountCodesUpdateCallback
useCartLinesAddCallback
useCartLinesRemoveCallback
useCartLinesTotalQuantity
useCartLinesUpdateCallback
useCartNoteUpdateCallback
Example
- import {useCartCheckoutUrl} from '@shopify/hydrogen'
+ import {useCart} from '@shopify/hydrogen'
- const checkoutUrl = useCartCheckoutUrl()
+ const {checkoutUrl} = useCart()
Render props removed
The following components no longer allow the function-as-a-child
(also known as "render props") pattern; see #589.
<Money>
: UseuseMoney
for customization.<CartLinePrice>
: UseuseMoney
for customization.<ProductPrice>
: UseuseMoney
for customization.<SelectedVariantPrice>
: UseuseMoney
for customization.<Metafield>
: UseuseParsedMetafields
for customization.<ProductMetafield>
: UseuseParsedMetafields
for customization.<SelectedVariantMetafield>
: UseuseParsedMetafields
for customization.<UnitPrice>
: UseuseMoney
for customization.<CartLines>
: UseuseCart
for customization.
Example
-import {Money} from '@shopify/hydrogen/client';
+import {useMoney} from '@shopify/hydrogen/client';
export default function MoneyCompareAtPrice({money}) {
+ const {amount, currencyNarrowSymbol} = useMoney(money);
return (
- <Money money={money}>
- {({amount, currencyNarrowSymbol}) => (
<span className="line-through text-lg mr-2.5 text-gray-500">
{currencyNarrowSymbol}
{amount}
</span>
- )}
- </Money>
);
}
Product and Cart component aliases removed
The following aliases have been removed. Use each component's original name:
Product
: UseProductProvider
instead.Product.Description
: UseProductDescription
instead.Product.Price
: UseProductPrice
instead.Product.Title
: UseProductTitle
instead.Product.Metafield
: UseProductMetafield
instead.Product.SelectedVariant.AddToCartButton
: UseSelectedVariantAddToCartButton
instead.Product.SelectedVariant.BuyNowButton
: UseSelectedVariantBuyNowButton
instead.Product.SelectedVariant.ShopPayButton
: UseSelectedVariantShopPayButton
instead.Product.SelectedVariant.Price
: UseSelectedVariantPrice
instead.Product.SelectedVariant.Image
UseSelectedVariantImage
instead.Product.SelectedVariant.UnitPrice
: UseSelectedVariantUnitPrice
instead.Product.SelectedVariant.Metafield
: UseSelectedVariantMetafield
instead.Cart
: UseCartProvider
instead.CartLine.Image
: UseCartLineImage
instead.CartLine.Price
: UseCartLinePrice
instead.CartLine.ProductTitle
: UseCartLineProductTitle
instead.CartLine.Quantity
: UseCartLineQuantity
instead.CartLine.QuantityAdjustButton
: UseCartLineQuantityAdjustButton
instead.CartLine.SelectedOptions
: UseCartLineSelectedOptions
instead.CartLine.Attributes
: UseCartLineAttributes
instead.
Example
- import {Product} from '@shopify/hydrogen'
+ import {ProductProvider, ProductImage} from '@shopify/hydrogen'
- <Product>
- <Product.Image/>
- </Product>
...
v0.10.1
This is a follow-up to our v0.10.0 release with a few high priority bug fixes. A few new features made it in as well!
What's Changed
- docs: update wrangler.toml to include new compatibility flag by @jplhomer in Shopify/hydrogen#536
- chore: update yarn lock by @blittle in Shopify/hydrogen#537
- [Hydrogen docs]: Update
master
references tomain
by @mcvinci in Shopify/hydrogen#541 - fix: remove deprecated survey monkey link by @cartogram in Shopify/hydrogen#556
- fix: wrong prop in HelmetProvider breaking SEO by @frandiox in Shopify/hydrogen#553
- Fix HMR for new page files by @frandiox in Shopify/hydrogen#554
- feat: more helpful preview error by @cartogram in Shopify/hydrogen#557
- feat: support basic CLI hooks by @cartogram in https://github.com/Shopify/hydrogen/pull/532
Full Changelog: Shopify/hydrogen@v0.10.0...v0.10.1
v0.10.0
Hydrogen v0.10 includes a new server components strategy, a new local preview command, and several important breaking changes. Please read the changes carefully to learn how to upgrade. Thank you for helping us improve Hydrogen during the developer preview!
What's Changed
✨ New Hydrogen apps will includes a yarn preview
command! This runs a local version of a sandboxed v8 runtime that mimics production runtimes like Oxygen and Cloudflare Workers. To test it in a new project, run yarn build && yarn preview
. For existing apps, run yarn build && npx @shopify/hydrogen-cli preview
. This requires Node >= v16.
Breaking Changes:
- Hydrogen now uses Meta's experimental version of React Server Components. Make sure to upgrade
react
andreact-dom
to the latest experimental version:yarn add @shopify/hydrogen [email protected] [email protected]
- We've removed react-router on the server. Instead of relying on
useParams()
to get URL parameters, params are passed directly to page server components:
export default function Product() {
const { handle } = useParams();
...
}
// changes to
export default function Product({ params }) {
const { handle } = params;
...
}
- Shopify configuration should no longer be imported and passed inside
App.server.jsx
, but instead inentry-client.jsx
andentry-server.jsx
:
// /App.server.jsx
import {DefaultRoutes} from '@shopify/hydrogen';
import {Suspense} from 'react';
import DefaultSeo from './components/DefaultSeo.server';
import NotFound from './components/NotFound.server';
import AppClient from './App.client';
import LoadingFallback from './components/LoadingFallback';
export default function App({log, pages, ...serverState}) {
return (
<Suspense fallback={<LoadingFallback />}>
<AppClient helmetContext={serverState.helmetContext}>
<DefaultSeo />
<DefaultRoutes
pages={pages}
serverState={serverState}
log={log}
fallback={<NotFound />}
/>
</AppClient>
</Suspense>
);
}
// /entry-server.jsx
import renderHydrogen from '@shopify/hydrogen/entry-server';
import shopifyConfig from '../shopify.config';
import App from './App.server';
const pages = import.meta.globEager('./pages/**/*.server.[jt](s|sx)');
export default renderHydrogen(App, {shopifyConfig, pages});
// /entry-client.jsx
import renderHydrogen from '@shopify/hydrogen/entry-client';
import shopifyConfig from '../shopify.config';
function ClientApp({children}) {
return children;
}
export default renderHydrogen(ClientApp, {shopifyConfig});
- There's a new
App.client.jsx
component:
// /App.client.jsx
import {HelmetProvider} from '@shopify/hydrogen/client';
import CartProvider from './components/CartProvider.client';
/**
* Setup client context, though the children are most likely server components
*/
export default function ClientApp({helmetContext, children}) {
return (
<HelmetProvider context={helmetContext}>
<CartProvider>{children}</CartProvider>
</HelmetProvider>
);
}
locale
is nowdefaultLocale
inshopify.config.js
graqhqlApiVersion
is nowstorefrontApiVersion
inshopify.config.js
- If you’re using the starter template layout component, remove the useCartUI hook:
// /src/components/Layout.server.jsx
import {
Image,
useShopQuery,
flattenConnection,
LocalizationProvider,
} from '@shopify/hydrogen';
import gql from 'graphql-tag';
import Header from './Header.client';
import Footer from './Footer.server';
import Cart from './Cart.client';
import {Suspense} from 'react';
/**
* A server component that defines a structure and organization of a page that can be used in different parts of the Hydrogen app
*/
export default function Layout({children, hero}) {
const {data} = useShopQuery({
query: QUERY,
variables: {
numCollections: 3,
},
cache: {
maxAge: 60,
staleWhileRevalidate: 60 * 10,
},
});
const collections = data ? flattenConnection(data.collections) : null;
const products = data ? flattenConnection(data.products) : null;
const storeName = data ? data.shop.name : '';
return (
<LocalizationProvider>
<div className="absolute top-0 left-0">
<a
href="#mainContent"
className="p-4 focus:block sr-only focus:not-sr-only"
>
Skip to content
</a>
</div>
<div className="min-h-screen max-w-screen text-gray-700 font-sans">
{/* TODO: Find out why Suspense needs to be here to prevent hydration errors. */}
<Suspense fallback={null}>
<Header collections={collections} storeName={storeName} />
<Cart />
</Suspense>
<main role="main" id="mainContent" className="relative bg-gray-50">
{hero}
<div className="mx-auto max-w-7xl p-4 md:py-5 md:px-8">
{children}
</div>
</main>
<Footer collection={collections[0]} product={products[0]} />
</div>
</LocalizationProvider>
);
}
const QUERY = gql`
query indexContent($numCollections: Int!) {
shop {
name
}
collections(first: $numCollections) {
edges {
node {
description
handle
id
title
image {
...ImageFragment
}
}
}
}
products(first: 1) {
edges {
node {
handle
}
}
}
}
${Image.Fragment}
`;
All changes:
- fix: warn instead of error on new or malformed page server components by @jplhomer in Shopify/hydrogen#495
- feat: implement upstream version of server components by @jplhomer in Shopify/hydrogen#498
- feat: add mini-oxygen preview script (alt) by @jplhomer in Shopify/hydrogen#493
- chore: remove dev by @jplhomer in Shopify/hydrogen#499
- Renamed 'locale' to 'defaultLocale' in shopify.config.js by @michenly in Shopify/hydrogen#496
- Add experimental publish pipeline by @jplhomer in Shopify/hydrogen#500
- fix: ensure runtime deps for CLI are included in deps, not devDeps by @jplhomer in https://github.com/Shopify/hydrogen/pull/501
- chore: try to fix CI issues on Windows by @jplhomer in Shopify/hydrogen#516
- chore(deps): bump nanoid from 3.1.30 to 3.2.0 by @dependabot in Shopify/hydrogen#508
- fix: do not mutate project upon running any CLI command by @jplhomer in Shopify/hydrogen#505
- fix: use MemoryStorage and Cache plugin for cache support in preview by @jplhomer in Shopify/hydrogen#504
- Update Node 14 -> 16 by @rafaelstz in Shopify/hydrogen#518
- fix: do not add CLI as a dep in the starter due to Node 16 requirements by @jplhomer in Shopify/hydrogen#517
- fix: bump to latest React experimental to include SSR Context bugfix by @jplhomer in Shopify/hydrogen#521
- dx: rename graphqlApiVersion to storefrontApiVersion by @frehner in Shopify/hydrogen#470
- [Hydrogen reference]: Regenerate docs by @mcvinci in Shopify/hydrogen#507
- Fix API Routes hot reloading and improvements to API route responses by @blittle in Shopify/hydrogen#524
- fix: use web streams polyfill in Node middleware so we can support Node v14 by @jplhomer in Shopify/hydrogen#527
- docs: update routing docs to remove react-router by @blittle in Shopify/hydrogen#525
- feat: add
dev
command to CLI by @cartogram in Shopify/hydrogen#530 - [Hydrogen docs]: Using
Context
in React Server Components by @mcvinci in Shopify/hydrogen#487 - [Hydrogen docs]: Remove references to React Router by @mcvinci in Shopify/hydrogen#489
New Contributors
- @michenly made their first contribution in Shopify/hydrogen#496
Full Changelog: Shopify/hydrogen@v0.9.1...v0.10.0
v0.9.1
What's Changed
- fix: revert to node-fetch so that hydrogen runs on node-12 by @blittle in Shopify/hydrogen#492
Once stackblitz offers Node 16 in their hosted container, we will again move to support node 16.5.0 or higher.
Full Changelog: Shopify/hydrogen@v0.9.0...v0.9.1
v0.9.0
Breaking Changes
Hydrogen now requires Node 16.5.0 or later. This is because Hydrogen relies on ReadableStreams.
What's Changed
- Optional purge cache on build by @wizardlyhel in Shopify/hydrogen#451
- [Hydrogen docs]: Regenerate reference by @mcvinci in Shopify/hydrogen#468
- [Hydrogen reference]: Specify
initialVariantId
prop as optional by @mcvinci in Shopify/hydrogen#469 - [Hydrogen reference]: Clarify required usage of
initialVariantId
prop by @mcvinci in Shopify/hydrogen#471 - chore: delete hydrogen-plugin-sanity by @hdoro in Shopify/hydrogen#363
- chore(deps-dev): bump shelljs from 0.8.4 to 0.8.5 by @dependabot in Shopify/hydrogen#474
- feat: Support local commands in CLI by @cartogram in Shopify/hydrogen#432
- [Hydrogen reference]: Tailwind benefits by @mcvinci in Shopify/hydrogen#473
- [Hydrogen reference]: React Server Components docs revised by @mcvinci in Shopify/hydrogen#464
- [Hydrogen docs]: Fix links by @mcvinci in Shopify/hydrogen#477
- feat: implement API routes by @blittle in Shopify/hydrogen#391
- Update Dockerfile from the example by @Francismori7 in Shopify/hydrogen#483
- [Hydrogen docs]: Add information about API routes by @mcvinci in Shopify/hydrogen#481
New Contributors
- @dependabot made their first contribution in Shopify/hydrogen#474
- @Francismori7 made their first contribution in Shopify/hydrogen#483
Full Changelog: Shopify/hydrogen@v0.8.3...v0.9.0
v0.8.3
What's Changed
- ci: prettier ignore lerna.json to stop breaking CI after publishing by @frehner in Shopify/hydrogen#442
- fix: replace log abbreviations with full text by @sahilmob in Shopify/hydrogen#411
- CLI
check
andadd
commands by @cartogram in Shopify/hydrogen#303 - feat: get translated content by @bitforcesrl in Shopify/hydrogen#397
- fix: warn instead of error when the app takes longer than 3s #408 by @blittle in Shopify/hydrogen#410
- fix: cli init create missing directory by @cartogram in Shopify/hydrogen#448
- Force file formatting parser in cli by @cartogram in Shopify/hydrogen#446
- fix: yarn scripts cli path by @cartogram in Shopify/hydrogen#447
- fix: remove redundant CLI tests by @cartogram in Shopify/hydrogen#456
- fix: flakey check test by @cartogram in Shopify/hydrogen#457
- fix: add npm-run-all as a dev dependency (for run-p) by @Aslemammad in Shopify/hydrogen#453
New Contributors
- @bitforcesrl made their first contribution in Shopify/hydrogen#397
- @Aslemammad made their first contribution in Shopify/hydrogen#453
Full Changelog: Shopify/hydrogen@v0.8.2...v0.8.3
v0.8.2
This version of Hydrogen fixes an issue with how Object IDs are decoded in the unstable
version of the Storefront API.
The Storefront API recently began using unencoded Object IDs in the unstable
version.
Existing Hydrogen apps should update to this version of Hydrogen to ensure their components continue to work against unstable
branch of Hydrogen.
yarn add @shopify/hydrogen
What's Changed
- Usequery errors by @frehner in Shopify/hydrogen#402
- Load logger only once by @frandiox in Shopify/hydrogen#407
- test: fix and run unit test for CartLineQuantityAdjustButton by @frehner in Shopify/hydrogen#366
- feat: root level examples directory by @cartogram in Shopify/hydrogen#422
- Update README.md by @morganmccunn in Shopify/hydrogen#428
- fix: do not attempt to decode Product IDs. by @jplhomer in Shopify/hydrogen#434
New Contributors
- @morganmccunn made their first contribution in Shopify/hydrogen#428
Full Changelog: Shopify/hydrogen@v0.8.1...v0.8.2
v0.8.1
Upgrade Guide
Hydrogen v0.8.1 switches to the React experimental build 2021-11-25. You will need to update your version of react
and react-dom
in order to use Hydrogen v0.8.1:
yarn add @shopify/hydrogen [email protected] [email protected]
The Hydrogen starter template also switched to Tailwind v3. You can update your own apps by following the Tailwind upgrade guide.
Features
- Logging: A new logging tool is available! View PR. Documentation coming soon.
What's Changed
- chore: allow merge commit messages by @frandiox in Shopify/hydrogen#343
- chore: upgrade to latest React 18 experimental version by @frandiox in Shopify/hydrogen#312
- feat: Use actions build-in cache in CI by @cartogram in Shopify/hydrogen#339
- fix: flakey test by @cartogram in Shopify/hydrogen#344
- chore: remove react testing-library by @cartogram in Shopify/hydrogen#345
- chore: rename/reorg spec => test files for consistency by @cartogram in Shopify/hydrogen#348
- chore: remove noise in test log output by @cartogram in Shopify/hydrogen#349
- Generate
useShopQuery
docs by @mcvinci in Shopify/hydrogen#353 - fix: cart decrease button removes at zero quantity by @alexeagleson in Shopify/hydrogen#351
- feat: use @shopify/docs-tools for docs dependency graph walk by @cartogram in Shopify/hydrogen#338
- [Hydrogen starter template]: Add descriptions for components by @mcvinci in Shopify/hydrogen#354
- chore: deprecate Sanity plugin and point to Sanity's version instead by @jplhomer in Shopify/hydrogen#360
- feat: implement Oxygen.env for runtime variables by @frandiox in Shopify/hydrogen#304
- fix: docs util for grabbing first sentence of ts-doc comment by @cartogram in Shopify/hydrogen#374
- docs: product provider tweaks by @scottdixon in Shopify/hydrogen#377
- feat: primitive hooks overview docs by @cartogram in Shopify/hydrogen#373
- [Hydrogen docs]: Hooks overview tables by @mcvinci in Shopify/hydrogen#382
- feat: detect bot user agents (e.g. googlebot) and change the response type accordingly by @frehner in Shopify/hydrogen#380
- Document naming conventions by @gfscott in Shopify/hydrogen#376
- ci: Add format checking in PR CI jobs by @frehner in Shopify/hydrogen#384
- feat: upgrade to Tailwind v3 by @jplhomer in Shopify/hydrogen#350
- Add logging abstraction by @blittle in Shopify/hydrogen#365
New Contributors
- @alexeagleson made their first contribution in Shopify/hydrogen#351
- @frehner made their first contribution in Shopify/hydrogen#380
- @gfscott made their first contribution in Shopify/hydrogen#376
Full Changelog: Shopify/hydrogen@v0.8.0...v0.8.1
v0.8.0
Hydrogen v0.8.0 makes some minor updates and adds compatibility for Vite v2.7.
Upgrade instructions
yarn add @shopify/hydrogen
(ornpm install @shopify/hydrogen
) to update to the latest versionyarn add -D vite
yarn dev --force
during your next development server to clear cache
Removal of react-query
Hydrogen no longer uses react-query
to power Suspense data fetching on the server. However, there should be no breaking changes as useQuery
and useShopQuery
are still offered.
If you previously depended upon react-query
in the server or the client of your app, you will need to install react-query
manually.
What's Changed
- Remove react-query by @wizardlyhel in Shopify/hydrogen#305
- fix: export CartLineSelectedOptions by @jplhomer in Shopify/hydrogen#325
- Fix framework suspense by @calirvine in Shopify/hydrogen#311
- chore: skip flaky test for productivity reasons by @jplhomer in Shopify/hydrogen#333
- fix: lowercase index page name by @jplhomer in Shopify/hydrogen#334
- Vite 2.7 compatibility by @jplhomer in Shopify/hydrogen#236
- feat: Generate component overview tables in shopify-dev docs by @cartogram in Shopify/hydrogen#327
New Contributors
- @calirvine made their first contribution in Shopify/hydrogen#311
Full Changelog: Shopify/hydrogen@v0.7.1...v0.8.0
v0.7.1
What's Changed
- fix: ESLint package use in starter by @cartogram in Shopify/hydrogen#290
- [Hydrogen docs]: Improve split between conceptual and reference content by @mcvinci in Shopify/hydrogen#284
- fix: update @vitejs/plugin-react to fix sourcemaps and remove workaround by @frandiox in Shopify/hydrogen#301
- fix: convert server components to shared components by @jplhomer in Shopify/hydrogen#292
- fix: avoid repeating the same identifier for default and named exports by @frandiox in Shopify/hydrogen#302
- chore: Update
graphql
dependency by @cartogram in Shopify/hydrogen#297 - feat(useShopQuery): allow optional queries w/o API calls by @hdoro in Shopify/hydrogen#242
- fix: variable not declared in 404 page. Closes #298 by @rafaelstz in Shopify/hydrogen#299
- chore: explicitly export types by @jplhomer in Shopify/hydrogen#315
New Contributors
- @hdoro made their first contribution in Shopify/hydrogen#242
Full Changelog: Shopify/hydrogen@v0.7.0...v0.7.1