@shopify/hydrogen 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +310 -26
- package/dist/esnext/client.d.ts +2 -0
- package/dist/esnext/client.js +2 -0
- package/dist/esnext/components/CartLineProvider/context.d.ts +10 -10
- package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +1 -1
- package/dist/esnext/components/CartProvider/CartProvider.client.js +2 -1
- package/dist/esnext/components/CartProvider/cart-queries.d.ts +9 -0
- package/dist/esnext/components/CartProvider/cart-queries.js +876 -0
- package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +1 -1
- package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +1 -1
- package/dist/esnext/components/CartProvider/hooks.d.ts +1 -1
- package/dist/esnext/components/CartProvider/hooks.js +4 -1
- package/dist/esnext/components/CartProvider/types.d.ts +1 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +6 -5
- package/dist/esnext/components/ExternalVideo/ExternalVideo.js +5 -2
- package/dist/esnext/components/Image/Image.d.ts +14 -12
- package/dist/esnext/components/Image/Image.js +17 -14
- package/dist/esnext/components/Link/Link.client.d.ts +4 -5
- package/dist/esnext/components/Link/Link.client.js +5 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +1 -3
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.d.ts +0 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +2 -2
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +15 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationQuery.d.ts +1 -8
- package/dist/esnext/components/LocalizationProvider/index.d.ts +0 -1
- package/dist/esnext/components/LocalizationProvider/index.js +0 -1
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +4 -3
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +2 -2
- package/dist/esnext/components/Metafield/Metafield.client.js +8 -5
- package/dist/esnext/components/Metafield/types.d.ts +1 -1
- package/dist/esnext/components/ModelViewer/ModelViewer.client.d.ts +57 -56
- package/dist/esnext/components/ModelViewer/ModelViewer.client.js +10 -4
- package/dist/esnext/components/Money/Money.client.d.ts +5 -4
- package/dist/esnext/components/Money/Money.client.js +1 -1
- package/dist/esnext/components/ProductDescription/ProductDescription.client.d.ts +9 -4
- package/dist/esnext/components/ProductDescription/ProductDescription.client.js +4 -3
- package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +3 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +2 -2
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +3 -2
- package/dist/esnext/components/ProductProvider/ProductProvider.client.js +1 -0
- package/dist/esnext/components/ProductProvider/context.d.ts +23 -14
- package/dist/esnext/components/Seo/CollectionSeo.client.d.ts +3 -2
- package/dist/esnext/components/Seo/CollectionSeo.client.js +2 -2
- package/dist/esnext/components/Seo/DefaultPageSeo.client.d.ts +3 -2
- package/dist/esnext/components/Seo/DescriptionSeo.client.d.ts +2 -2
- package/dist/esnext/components/Seo/HomePageSeo.client.d.ts +1 -1
- package/dist/esnext/components/Seo/ImageSeo.client.d.ts +3 -2
- package/dist/esnext/components/Seo/ImageSeo.client.js +1 -1
- package/dist/esnext/components/Seo/PageSeo.client.d.ts +3 -2
- package/dist/esnext/components/Seo/ProductSeo.client.d.ts +3 -3
- package/dist/esnext/components/Seo/ProductSeo.client.js +10 -5
- package/dist/esnext/components/Seo/Seo.client.d.ts +10 -7
- package/dist/esnext/components/Seo/TitleSeo.client.d.ts +3 -4
- package/dist/esnext/components/Seo/TwitterSeo.client.d.ts +1 -1
- package/dist/esnext/components/Seo/seo-types.d.ts +17 -0
- package/dist/esnext/components/{ExternalVideo/ExternalVideoFragment.js → Seo/seo-types.js} +0 -0
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +7 -6
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +1 -1
- package/dist/esnext/components/Video/Video.d.ts +5 -4
- package/dist/esnext/components/Video/Video.js +10 -2
- package/dist/esnext/components/index.d.ts +0 -3
- package/dist/esnext/components/index.js +0 -3
- package/dist/esnext/entry-client.js +9 -4
- package/dist/esnext/entry-server.js +99 -87
- package/dist/esnext/foundation/FileRoutes/FileRoutes.server.d.ts +22 -0
- package/dist/esnext/foundation/{Router/FileRoutes.js → FileRoutes/FileRoutes.server.js} +20 -10
- package/dist/esnext/foundation/Redirect/Redirect.client.d.ts +5 -0
- package/dist/esnext/foundation/Redirect/Redirect.client.js +14 -0
- package/dist/esnext/foundation/Route/Route.server.d.ts +12 -0
- package/dist/esnext/foundation/Route/Route.server.js +33 -0
- package/dist/esnext/foundation/Router/{Router.d.ts → BrowserRouter.client.d.ts} +3 -2
- package/dist/esnext/foundation/Router/{Router.js → BrowserRouter.client.js} +7 -5
- package/dist/esnext/foundation/Router/Router.server.d.ts +5 -3
- package/dist/esnext/foundation/Router/Router.server.js +7 -22
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +19 -24
- package/dist/esnext/foundation/ShopifyProvider/index.d.ts +0 -1
- package/dist/esnext/foundation/ShopifyProvider/index.js +0 -1
- package/dist/esnext/foundation/index.d.ts +0 -1
- package/dist/esnext/foundation/index.js +0 -1
- package/dist/esnext/{hooks → foundation}/useNavigate/useNavigate.d.ts +6 -3
- package/dist/esnext/{hooks → foundation}/useNavigate/useNavigate.js +4 -1
- package/dist/esnext/foundation/useQuery/hooks.d.ts +2 -4
- package/dist/esnext/foundation/useQuery/hooks.js +5 -2
- package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.d.ts +9 -0
- package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.js +7 -0
- package/dist/esnext/foundation/useRouteParams/useRouteParams.d.ts +4 -0
- package/dist/esnext/foundation/useRouteParams/useRouteParams.js +9 -0
- package/dist/esnext/foundation/useUrl/useUrl.js +1 -1
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +6 -0
- package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +5 -0
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +4 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +5 -0
- package/dist/esnext/framework/middleware.js +25 -3
- package/dist/esnext/framework/plugin.js +6 -1
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.d.ts +2 -0
- package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.js +28 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +61 -75
- package/dist/esnext/framework/plugins/vite-plugin-platform-entry.js +1 -1
- package/dist/esnext/hooks/index.d.ts +0 -1
- package/dist/esnext/hooks/index.js +0 -1
- package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +10 -10
- package/dist/esnext/hooks/useCountry/useCountry.d.ts +4 -4
- package/dist/esnext/hooks/useMoney/hooks.d.ts +3 -3
- package/dist/esnext/hooks/useMoney/hooks.js +2 -2
- package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +17 -2
- package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.js +7 -3
- package/dist/esnext/hooks/useProduct/useProduct.d.ts +34 -96
- package/dist/esnext/hooks/useProductOptions/helpers.d.ts +6 -4
- package/dist/esnext/hooks/useProductOptions/helpers.js +13 -6
- package/dist/esnext/hooks/useProductOptions/types.d.ts +15 -35
- package/dist/esnext/hooks/useProductOptions/useProductOptions.d.ts +6 -5
- package/dist/esnext/hooks/useProductOptions/useProductOptions.js +13 -3
- package/dist/esnext/hooks/useShopQuery/hooks.js +47 -7
- package/dist/esnext/index.d.ts +7 -5
- package/dist/esnext/index.js +7 -5
- package/dist/esnext/platforms/worker-event.d.ts +0 -8
- package/dist/esnext/platforms/worker-event.js +2 -23
- package/dist/esnext/platforms/worker.d.ts +14 -0
- package/dist/esnext/platforms/worker.js +24 -0
- package/dist/esnext/{graphql/types/types.d.ts → storefront-api-types.d.ts} +389 -32
- package/dist/esnext/{graphql/types/types.js → storefront-api-types.js} +326 -30
- package/dist/esnext/streaming.server.d.ts +9 -5
- package/dist/esnext/streaming.server.js +2 -18
- package/dist/esnext/types.d.ts +1 -16
- package/dist/esnext/utilities/apiRoutes.d.ts +5 -1
- package/dist/esnext/utilities/apiRoutes.js +2 -3
- package/dist/esnext/utilities/devtools.d.ts +11 -0
- package/dist/esnext/utilities/devtools.js +11 -0
- package/dist/esnext/utilities/fetch.d.ts +7 -1
- package/dist/esnext/utilities/fetch.js +9 -10
- package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +3 -2
- package/dist/esnext/utilities/flattenConnection/flattenConnection.js +9 -2
- package/dist/esnext/utilities/graphql-tracker.d.ts +17 -0
- package/dist/esnext/utilities/graphql-tracker.js +119 -0
- package/dist/esnext/utilities/image_size.d.ts +5 -4
- package/dist/esnext/utilities/log/log-query-timeline.d.ts +1 -1
- package/dist/esnext/utilities/log/log-query-timeline.js +1 -2
- package/dist/esnext/utilities/log/log.d.ts +1 -0
- package/dist/esnext/utilities/log/utils.js +3 -0
- package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +3 -2
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/entry-server.js +104 -88
- package/dist/node/foundation/Redirect/Redirect.client.d.ts +5 -0
- package/dist/node/foundation/Redirect/Redirect.client.js +17 -0
- package/dist/node/foundation/Router/BrowserRouter.client.d.ts +13 -0
- package/dist/node/foundation/Router/BrowserRouter.client.js +77 -0
- package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +24 -25
- package/dist/node/foundation/ServerRequestProvider/index.js +5 -1
- package/dist/node/foundation/ServerStateProvider/ServerStateProvider.js +5 -1
- package/dist/node/foundation/ssr-interop.d.ts +29 -0
- package/dist/node/foundation/ssr-interop.js +39 -0
- package/dist/node/foundation/useNavigate/useNavigate.d.ts +13 -0
- package/dist/node/foundation/useNavigate/useNavigate.js +18 -0
- package/dist/node/foundation/useServerState/index.d.ts +1 -0
- package/dist/node/foundation/useServerState/index.js +5 -0
- package/dist/node/foundation/useServerState/use-server-state.d.ts +16 -0
- package/dist/node/foundation/useServerState/use-server-state.js +24 -0
- package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +6 -0
- package/dist/node/framework/Hydration/ServerComponentRequest.server.js +5 -0
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +4 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +8 -0
- package/dist/node/framework/middleware.js +30 -4
- package/dist/node/framework/plugin.js +11 -2
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.d.ts +2 -0
- package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.js +31 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +61 -75
- package/dist/node/framework/plugins/vite-plugin-platform-entry.js +1 -1
- package/dist/node/{graphql/types/types.d.ts → storefront-api-types.d.ts} +389 -32
- package/dist/node/{graphql/types/types.js → storefront-api-types.js} +327 -31
- package/dist/node/streaming.server.d.ts +9 -5
- package/dist/node/streaming.server.js +2 -18
- package/dist/node/types.d.ts +1 -16
- package/dist/node/utilities/apiRoutes.d.ts +5 -1
- package/dist/node/utilities/apiRoutes.js +2 -3
- package/dist/node/utilities/fetch.d.ts +7 -1
- package/dist/node/utilities/fetch.js +9 -10
- package/dist/node/utilities/log/log-query-timeline.d.ts +1 -1
- package/dist/node/utilities/log/log-query-timeline.js +1 -2
- package/dist/node/utilities/log/log.d.ts +1 -0
- package/dist/node/utilities/log/utils.js +3 -0
- package/dist/node/utilities/web-api-polyfill.js +5 -1
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/package.json +9 -12
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +43 -104
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js +1566 -848
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js +36 -421
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.development.server.js +1523 -864
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.production.min.server.js +35 -437
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.development.js +507 -517
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.production.min.js +10 -246
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +16 -23
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +47 -108
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.browser.server.js +1033 -306
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.node.server.js +965 -293
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite.js +98 -108
- package/vendor/react-server-dom-vite/package.json +0 -2
- package/dist/esnext/components/ExternalVideo/ExternalVideoFragment.d.ts +0 -8
- package/dist/esnext/components/Image/ImageFragment.d.ts +0 -8
- package/dist/esnext/components/Image/ImageFragment.js +0 -1
- package/dist/esnext/components/MediaFile/MediaFileFragment.d.ts +0 -36
- package/dist/esnext/components/MediaFile/MediaFileFragment.js +0 -1
- package/dist/esnext/components/Metafield/MetafieldFragment.d.ts +0 -22
- package/dist/esnext/components/Metafield/MetafieldFragment.js +0 -1
- package/dist/esnext/components/ModelViewer/Model3DFragment.d.ts +0 -15
- package/dist/esnext/components/ModelViewer/Model3DFragment.js +0 -1
- package/dist/esnext/components/Money/MoneyFragment.d.ts +0 -8
- package/dist/esnext/components/Money/MoneyFragment.js +0 -1
- package/dist/esnext/components/ProductProvider/ProductProviderFragment.d.ts +0 -247
- package/dist/esnext/components/ProductProvider/ProductProviderFragment.js +0 -1
- package/dist/esnext/components/ProductProvider/types.d.ts +0 -19
- package/dist/esnext/components/ProductProvider/types.js +0 -1
- package/dist/esnext/components/RawHtml/RawHtml.d.ts +0 -17
- package/dist/esnext/components/RawHtml/RawHtml.js +0 -21
- package/dist/esnext/components/RawHtml/index.d.ts +0 -1
- package/dist/esnext/components/RawHtml/index.js +0 -1
- package/dist/esnext/components/Seo/SeoFragment.d.ts +0 -66
- package/dist/esnext/components/Seo/SeoFragment.js +0 -1
- package/dist/esnext/components/Seo/types.d.ts +0 -15
- package/dist/esnext/components/Seo/types.js +0 -1
- package/dist/esnext/components/UnitPrice/UnitPriceFragment.d.ts +0 -15
- package/dist/esnext/components/UnitPrice/UnitPriceFragment.js +0 -1
- package/dist/esnext/components/Video/VideoFragment.d.ts +0 -15
- package/dist/esnext/components/Video/VideoFragment.js +0 -1
- package/dist/esnext/foundation/Router/FileRoutes.d.ts +0 -18
- package/dist/esnext/foundation/Router/Route.server.d.ts +0 -9
- package/dist/esnext/foundation/Router/Route.server.js +0 -6
- package/dist/esnext/foundation/Router/useParams.d.ts +0 -1
- package/dist/esnext/foundation/Router/useParams.js +0 -5
- package/dist/esnext/fragments.d.ts +0 -20
- package/dist/esnext/fragments.js +0 -10
- package/dist/esnext/graphql/graphql-constants.d.ts +0 -1756
- package/dist/esnext/graphql/graphql-constants.js +0 -3447
- package/dist/esnext/hooks/useAvailableCountries/index.d.ts +0 -1
- package/dist/esnext/hooks/useAvailableCountries/index.js +0 -1
- package/dist/esnext/hooks/useAvailableCountries/useAvailableCountries.d.ts +0 -11
- package/dist/esnext/hooks/useAvailableCountries/useAvailableCountries.js +0 -17
- package/dist/esnext/hooks/useNavigate/index.d.ts +0 -1
- package/dist/esnext/hooks/useNavigate/index.js +0 -1
- package/dist/esnext/hooks/useProductOptions/SellingPlanFragment.d.ts +0 -31
- package/dist/esnext/hooks/useProductOptions/SellingPlanFragment.js +0 -1
- package/dist/esnext/hooks/useProductOptions/SellingPlanGroupsFragment.d.ts +0 -46
- package/dist/esnext/hooks/useProductOptions/SellingPlanGroupsFragment.js +0 -1
- package/dist/esnext/hooks/useProductOptions/VariantFragment.d.ts +0 -106
- package/dist/esnext/hooks/useProductOptions/VariantFragment.js +0 -1
- package/fragments.d.ts +0 -1
- package/fragments.js +0 -1
|
@@ -2,17 +2,19 @@ import { createBrowserHistory } from 'history';
|
|
|
2
2
|
import React, { createContext, useContext, useMemo, useState, useEffect, } from 'react';
|
|
3
3
|
import { META_ENV_SSR } from '../ssr-interop';
|
|
4
4
|
import { useServerState } from '../useServerState';
|
|
5
|
-
const RouterContext = createContext({});
|
|
5
|
+
export const RouterContext = createContext({});
|
|
6
6
|
let currentPath = '';
|
|
7
|
-
|
|
7
|
+
let isFirstLoad = true;
|
|
8
|
+
export const BrowserRouter = ({ history: pHistory, children, }) => {
|
|
9
|
+
if (META_ENV_SSR)
|
|
10
|
+
return React.createElement(React.Fragment, null, children);
|
|
8
11
|
const history = useMemo(() => pHistory || createBrowserHistory(), [pHistory]);
|
|
9
|
-
const [firstLoad, setFirstLoad] = useState(true);
|
|
10
12
|
const [location, setLocation] = useState(history.location);
|
|
11
13
|
const { pending, serverState, setServerState } = useServerState();
|
|
12
14
|
useEffect(() => {
|
|
13
15
|
// The app has just loaded
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
+
if (isFirstLoad)
|
|
17
|
+
isFirstLoad = false;
|
|
16
18
|
// A navigation event has just happened
|
|
17
19
|
else if (!pending && currentPath !== serverState.pathname) {
|
|
18
20
|
window.scrollTo(0, 0);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
declare type RouterProps = {
|
|
3
|
+
/** Any React elements. */
|
|
3
4
|
children: Array<ReactElement> | ReactElement;
|
|
4
|
-
serverProps: Record<string, any>;
|
|
5
|
-
fallback: ReactElement;
|
|
6
5
|
};
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The `Router` component provides the context for routing in your Hydrogen app.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Router({ children }: RouterProps): ReactElement;
|
|
8
10
|
export {};
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return recurseChildren(request, serverProps, fallback, currentPath, children);
|
|
9
|
-
}
|
|
10
|
-
function recurseChildren(request, serverProps, fallback, currentPath, children) {
|
|
11
|
-
for (const child of Children.toArray(children)) {
|
|
12
|
-
if (child.type === FileRoutes) {
|
|
13
|
-
const fileRoutingResult = child.type({ ...child.props, serverProps });
|
|
14
|
-
if (fileRoutingResult)
|
|
15
|
-
return (React.createElement(React.Fragment, null,
|
|
16
|
-
fileRoutingResult,
|
|
17
|
-
React.createElement(Boomerang, { pageTemplate: fileRoutingResult.type.name })));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return (React.createElement(React.Fragment, null,
|
|
21
|
-
fallback,
|
|
22
|
-
React.createElement(Boomerang, { pageTemplate: 'fallback' })));
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BrowserRouter } from './BrowserRouter.client';
|
|
3
|
+
/**
|
|
4
|
+
* The `Router` component provides the context for routing in your Hydrogen app.
|
|
5
|
+
*/
|
|
6
|
+
export function Router({ children }) {
|
|
7
|
+
return React.createElement(BrowserRouter, null, children);
|
|
23
8
|
}
|
|
@@ -25,16 +25,16 @@ export function ServerRequestProvider({ isRSC, request, children, }) {
|
|
|
25
25
|
export function useServerRequest() {
|
|
26
26
|
let request;
|
|
27
27
|
try {
|
|
28
|
-
//
|
|
29
|
-
request = useContext(RequestContextSSR);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
// If normal context failed it means this is not an SSR request.
|
|
33
|
-
// Try getting RSC cache instead:
|
|
28
|
+
// This cache only works during RSC rendering:
|
|
34
29
|
// @ts-ignore
|
|
35
30
|
const cache = React.unstable_getCacheForType(requestCacheRSC);
|
|
36
31
|
request = cache ? cache.get(requestCacheRSC.key) : null;
|
|
37
32
|
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
// If RSC cache failed it means this is not an RSC request.
|
|
35
|
+
// Try getting SSR context instead:
|
|
36
|
+
request = useContext(RequestContextSSR);
|
|
37
|
+
}
|
|
38
38
|
if (!request) {
|
|
39
39
|
// @ts-ignore
|
|
40
40
|
if (__DEV__ && typeof jest !== 'undefined') {
|
|
@@ -55,19 +55,19 @@ export function useRequestCacheData(key, fetcher) {
|
|
|
55
55
|
const cache = request.ctx.cache;
|
|
56
56
|
const cacheKey = hashKey(key);
|
|
57
57
|
if (!cache.has(cacheKey)) {
|
|
58
|
-
let
|
|
58
|
+
let result;
|
|
59
59
|
let promise;
|
|
60
60
|
cache.set(cacheKey, () => {
|
|
61
|
-
if (
|
|
61
|
+
if (result !== undefined) {
|
|
62
62
|
collectQueryTimings(request, key, 'rendered');
|
|
63
|
-
return
|
|
63
|
+
return result;
|
|
64
64
|
}
|
|
65
65
|
if (!promise) {
|
|
66
66
|
const startApiTime = getTime();
|
|
67
|
-
promise = fetcher().then((
|
|
68
|
-
|
|
67
|
+
promise = fetcher().then((data) => {
|
|
68
|
+
result = { data };
|
|
69
69
|
collectQueryTimings(request, key, 'resolved', getTime() - startApiTime);
|
|
70
|
-
}, (
|
|
70
|
+
}, (error) => (result = { error }));
|
|
71
71
|
}
|
|
72
72
|
throw promise;
|
|
73
73
|
});
|
|
@@ -84,25 +84,20 @@ export function preloadRequestCacheData(request, preloadQueries) {
|
|
|
84
84
|
preloadQueries === null || preloadQueries === void 0 ? void 0 : preloadQueries.forEach((preloadQuery, cacheKey) => {
|
|
85
85
|
collectQueryTimings(request, preloadQuery.key, 'preload');
|
|
86
86
|
if (!cache.has(cacheKey)) {
|
|
87
|
-
let
|
|
87
|
+
let result;
|
|
88
88
|
let promise;
|
|
89
89
|
cache.set(cacheKey, () => {
|
|
90
|
-
if (
|
|
90
|
+
if (result !== undefined) {
|
|
91
91
|
collectQueryTimings(request, preloadQuery.key, 'rendered');
|
|
92
|
-
return
|
|
92
|
+
return result;
|
|
93
93
|
}
|
|
94
94
|
if (!promise) {
|
|
95
95
|
const startApiTime = getTime();
|
|
96
|
-
promise = preloadQuery.fetcher().then((
|
|
97
|
-
|
|
96
|
+
promise = preloadQuery.fetcher().then((data) => {
|
|
97
|
+
result = { data };
|
|
98
98
|
collectQueryTimings(request, preloadQuery.key, 'resolved', getTime() - startApiTime);
|
|
99
|
-
}, (
|
|
100
|
-
|
|
101
|
-
// On Cloudfare, this happens when a Cache item has expired at max-age
|
|
102
|
-
//
|
|
103
|
-
// We need to remove this entry from cache so that render cycle will retry on its own
|
|
104
|
-
cache.delete(cacheKey);
|
|
105
|
-
collectQueryTimings(request, preloadQuery.key, 'expired', getTime() - startApiTime);
|
|
99
|
+
}, (error) => {
|
|
100
|
+
result = { error };
|
|
106
101
|
});
|
|
107
102
|
}
|
|
108
103
|
return promise;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
declare type NavigationOptions = {
|
|
2
|
-
/** Whether to update the state object or URL of the current history entry.
|
|
2
|
+
/** Whether to update the state object or URL of the current history entry. Defaults to false. */
|
|
3
3
|
replace?: boolean;
|
|
4
|
-
/** Whether to reload the whole document on navigation */
|
|
4
|
+
/** Whether to reload the whole document on navigation. */
|
|
5
5
|
reloadDocument?: boolean;
|
|
6
|
-
/** The custom client state with the navigation */
|
|
6
|
+
/** The custom client state with the navigation. */
|
|
7
7
|
clientState?: any;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* The useNavigate hook imperatively navigates between routes.
|
|
11
|
+
*/
|
|
9
12
|
export declare function useNavigate(): (path: string, options?: NavigationOptions) => void;
|
|
10
13
|
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { useRouter } from '
|
|
1
|
+
import { useRouter } from '../Router/BrowserRouter.client';
|
|
2
|
+
/**
|
|
3
|
+
* The useNavigate hook imperatively navigates between routes.
|
|
4
|
+
*/
|
|
2
5
|
export function useNavigate() {
|
|
3
6
|
const router = useRouter();
|
|
4
7
|
return (path, options = { replace: false, reloadDocument: false }) => {
|
|
@@ -14,7 +14,7 @@ export interface HydrogenUseQueryOptions {
|
|
|
14
14
|
* The `useQuery` hook executes an asynchronous operation like `fetch` in a way that
|
|
15
15
|
* supports [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html). It's based
|
|
16
16
|
* on [react-query](https://react-query.tanstack.com/reference/useQuery). You can use this
|
|
17
|
-
* hook to call any third-party APIs.
|
|
17
|
+
* hook to call any third-party APIs from a server component.
|
|
18
18
|
*/
|
|
19
19
|
export declare function useQuery<T>(
|
|
20
20
|
/** A string or array to uniquely identify the current query. */
|
|
@@ -24,9 +24,7 @@ queryFn: () => Promise<T>,
|
|
|
24
24
|
/** The options to manage the cache behavior of the sub-request. */
|
|
25
25
|
queryOptions?: HydrogenUseQueryOptions): {
|
|
26
26
|
data?: undefined;
|
|
27
|
-
error: Response;
|
|
28
|
-
* Attempt to read the query from cache. If it doesn't exist or if it's stale, regenerate it.
|
|
29
|
-
*/
|
|
27
|
+
error: Response;
|
|
30
28
|
} | {
|
|
31
29
|
data: T;
|
|
32
30
|
error?: undefined;
|
|
@@ -6,7 +6,7 @@ import { useRequestCacheData, useServerRequest } from '../ServerRequestProvider'
|
|
|
6
6
|
* The `useQuery` hook executes an asynchronous operation like `fetch` in a way that
|
|
7
7
|
* supports [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html). It's based
|
|
8
8
|
* on [react-query](https://react-query.tanstack.com/reference/useQuery). You can use this
|
|
9
|
-
* hook to call any third-party APIs.
|
|
9
|
+
* hook to call any third-party APIs from a server component.
|
|
10
10
|
*/
|
|
11
11
|
export function useQuery(
|
|
12
12
|
/** A string or array to uniquely identify the current query. */
|
|
@@ -16,7 +16,10 @@ queryFn,
|
|
|
16
16
|
/** The options to manage the cache behavior of the sub-request. */
|
|
17
17
|
queryOptions) {
|
|
18
18
|
const request = useServerRequest();
|
|
19
|
-
const withCacheIdKey = [
|
|
19
|
+
const withCacheIdKey = [
|
|
20
|
+
'__QUERY_CACHE_ID__',
|
|
21
|
+
...(typeof key === 'string' ? [key] : key),
|
|
22
|
+
];
|
|
20
23
|
const fetcher = cachedQueryFnBuilder(withCacheIdKey, queryFn, queryOptions);
|
|
21
24
|
collectQueryTimings(request, withCacheIdKey, 'requested');
|
|
22
25
|
if (queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.preload) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
declare type RouteParamsContextValue = {
|
|
3
|
+
routeParams: Record<string, string>;
|
|
4
|
+
};
|
|
5
|
+
export declare const RouteParamsContext: React.Context<RouteParamsContextValue>;
|
|
6
|
+
export declare const RouteParamsProvider: FC<{
|
|
7
|
+
routeParams: Record<string, string>;
|
|
8
|
+
}>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
|
+
export const RouteParamsContext = createContext({
|
|
3
|
+
routeParams: {},
|
|
4
|
+
});
|
|
5
|
+
export const RouteParamsProvider = ({ children, routeParams, }) => {
|
|
6
|
+
return (React.createElement(RouteParamsContext.Provider, { value: { routeParams } }, children));
|
|
7
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useEnvContext } from '../ssr-interop';
|
|
2
|
+
import { RouteParamsContext } from './RouteParamsProvider.client';
|
|
3
|
+
/**
|
|
4
|
+
* The `useRouteParams` hook retrieves the parameters of an active route. The hook is available in both server and client components.
|
|
5
|
+
*/
|
|
6
|
+
export function useRouteParams() {
|
|
7
|
+
const router = useEnvContext((req) => req.ctx.router, RouteParamsContext);
|
|
8
|
+
return router.routeParams;
|
|
9
|
+
}
|
|
@@ -9,7 +9,7 @@ export function useUrl() {
|
|
|
9
9
|
const serverUrl = new URL(useEnvContext((req) => req.url));
|
|
10
10
|
if (serverUrl.pathname === RSC_PATHNAME) {
|
|
11
11
|
const state = JSON.parse(serverUrl.searchParams.get('state') || '{}');
|
|
12
|
-
const parsedUrl = `${serverUrl.origin}
|
|
12
|
+
const parsedUrl = `${serverUrl.origin}${(_a = state.pathname) !== null && _a !== void 0 ? _a : ''}${(_b = state.search) !== null && _b !== void 0 ? _b : ''}`;
|
|
13
13
|
return new URL(parsedUrl);
|
|
14
14
|
}
|
|
15
15
|
return new URL(serverUrl);
|
|
@@ -10,6 +10,11 @@ export declare type PreloadQueryEntry = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare type PreloadQueriesByURL = Map<string, PreloadQueryEntry>;
|
|
12
12
|
export declare type AllPreloadQueries = Map<string, PreloadQueriesByURL>;
|
|
13
|
+
export declare type RouterContextData = {
|
|
14
|
+
routeRendered: boolean;
|
|
15
|
+
serverProps: Record<string, any>;
|
|
16
|
+
routeParams: Record<string, string>;
|
|
17
|
+
};
|
|
13
18
|
/**
|
|
14
19
|
* This augments the `Request` object from the Fetch API:
|
|
15
20
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
|
|
@@ -29,6 +34,7 @@ export declare class ServerComponentRequest extends Request {
|
|
|
29
34
|
queryCacheControl: Array<QueryCacheControlHeaders>;
|
|
30
35
|
queryTimings: Array<QueryTiming>;
|
|
31
36
|
preloadQueries: PreloadQueriesByURL;
|
|
37
|
+
router: RouterContextData;
|
|
32
38
|
[key: string]: any;
|
|
33
39
|
};
|
|
34
40
|
constructor(input: any);
|
|
@@ -38,6 +38,11 @@ export class ServerComponentRequest extends Request {
|
|
|
38
38
|
this.ctx = {
|
|
39
39
|
cache: new Map(),
|
|
40
40
|
head: new HeadData({}),
|
|
41
|
+
router: {
|
|
42
|
+
routeRendered: false,
|
|
43
|
+
serverProps: {},
|
|
44
|
+
routeParams: {},
|
|
45
|
+
},
|
|
41
46
|
queryCacheControl: [],
|
|
42
47
|
queryTimings: [],
|
|
43
48
|
preloadQueries: new Map(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CachingStrategy } from '../../types';
|
|
2
|
+
import React from 'react';
|
|
2
3
|
export declare class ServerComponentResponse extends Response {
|
|
3
4
|
private wait;
|
|
4
5
|
private cacheOptions?;
|
|
@@ -23,7 +24,9 @@ export declare class ServerComponentResponse extends Response {
|
|
|
23
24
|
statusText?: string;
|
|
24
25
|
headers?: Record<string, any>;
|
|
25
26
|
}): void;
|
|
26
|
-
redirect(location: string, status?: number):
|
|
27
|
+
redirect(location: string, status?: number): React.FunctionComponentElement<{
|
|
28
|
+
to: string;
|
|
29
|
+
}>;
|
|
27
30
|
/**
|
|
28
31
|
* Send the response from a Server Component. Renders React components to string,
|
|
29
32
|
* and returns `null` to make React happy.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { renderToString } from 'react-dom/server';
|
|
2
2
|
import { CacheSeconds, generateCacheControlHeader } from '../CachingStrategy';
|
|
3
|
+
import Redirect from '../../foundation/Redirect/Redirect.client';
|
|
4
|
+
import React from 'react';
|
|
3
5
|
export class ServerComponentResponse extends Response {
|
|
4
6
|
constructor() {
|
|
5
7
|
super(...arguments);
|
|
@@ -36,7 +38,10 @@ export class ServerComponentResponse extends Response {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
redirect(location, status = 307) {
|
|
41
|
+
// writeHead is used for SSR, so that the server responds with a redirect
|
|
39
42
|
this.writeHead({ status, headers: { location } });
|
|
43
|
+
// in the case of an RSC request, instead render a client component that will redirect
|
|
44
|
+
return React.createElement(Redirect, { to: location });
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
42
47
|
* Send the response from a Server Component. Renders React components to string,
|
|
@@ -8,11 +8,17 @@ export function graphiqlMiddleware({ shopifyConfig, dev, }) {
|
|
|
8
8
|
next();
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
let entrypointError = null;
|
|
11
12
|
/**
|
|
12
13
|
* Provides middleware to Node.js Express-like servers. Used by the Hydrogen
|
|
13
14
|
* Vite dev server plugin as well as production Node.js implementation.
|
|
14
15
|
*/
|
|
15
16
|
export function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypoint, devServer, }) {
|
|
17
|
+
if (dev && devServer) {
|
|
18
|
+
// Store this globally for devtools
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
globalThis.__viteDevServer = devServer;
|
|
21
|
+
}
|
|
16
22
|
/**
|
|
17
23
|
* We're running in the Node.js runtime without access to `fetch`,
|
|
18
24
|
* which is needed for proxy requests and server-side API requests.
|
|
@@ -24,8 +30,25 @@ export function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypo
|
|
|
24
30
|
var _a, _b, _c;
|
|
25
31
|
try {
|
|
26
32
|
await webPolyfills;
|
|
27
|
-
const entrypoint = await getServerEntrypoint()
|
|
28
|
-
|
|
33
|
+
const entrypoint = await Promise.resolve(getServerEntrypoint()).catch((error) => {
|
|
34
|
+
// Errors are only thrown the first time we try to load the entry point.
|
|
35
|
+
// After refreshing the browser, this just loads an empty module
|
|
36
|
+
// and doesn't throw anymore. Store this error in the outer scope
|
|
37
|
+
// to keep throwing it on refresh until things are fixed.
|
|
38
|
+
entrypointError = error;
|
|
39
|
+
});
|
|
40
|
+
const handleRequest = (_a = entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.default) !== null && _a !== void 0 ? _a : entrypoint;
|
|
41
|
+
if (typeof handleRequest !== 'function') {
|
|
42
|
+
if (entrypointError) {
|
|
43
|
+
throw entrypointError;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// This means there is no error when loading the entry point but
|
|
47
|
+
// we are still not getting a function as the default export.
|
|
48
|
+
throw new Error('Something is wrong in your project. Make sure to add "export default renderHydrogen(...)" in your server entry file.');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
entrypointError = null;
|
|
29
52
|
const eventResponse = await handleRequest(request, {
|
|
30
53
|
dev,
|
|
31
54
|
cache,
|
|
@@ -50,7 +73,6 @@ export function hydrogenMiddleware({ dev, cache, indexTemplate, getServerEntrypo
|
|
|
50
73
|
catch (e) {
|
|
51
74
|
if (dev && devServer)
|
|
52
75
|
devServer.ssrFixStacktrace(e);
|
|
53
|
-
console.log(e.stack);
|
|
54
76
|
response.statusCode = 500;
|
|
55
77
|
/**
|
|
56
78
|
* Attempt to print the error stack within the template.
|
|
@@ -10,6 +10,7 @@ import hydrationAutoImport from './plugins/vite-plugin-hydration-auto-import';
|
|
|
10
10
|
import inspect from 'vite-plugin-inspect';
|
|
11
11
|
import react from '@vitejs/plugin-react';
|
|
12
12
|
import path from 'path';
|
|
13
|
+
import cssModulesRsc from './plugins/vite-plugin-css-modules-rsc';
|
|
13
14
|
export default (shopifyConfig, pluginOptions = {}) => {
|
|
14
15
|
return [
|
|
15
16
|
process.env.VITE_INSPECT && inspect(),
|
|
@@ -19,6 +20,7 @@ export default (shopifyConfig, pluginOptions = {}) => {
|
|
|
19
20
|
react(),
|
|
20
21
|
hydrationAutoImport(),
|
|
21
22
|
ssrInterop(),
|
|
23
|
+
cssModulesRsc(),
|
|
22
24
|
rsc({
|
|
23
25
|
clientComponentPaths: [
|
|
24
26
|
path.join(path.dirname(require.resolve('@shopify/hydrogen/package.json'))),
|
|
@@ -29,7 +31,10 @@ export default (shopifyConfig, pluginOptions = {}) => {
|
|
|
29
31
|
const entryServer = process.env.HYDROGEN_SERVER_ENTRY || HYDROGEN_DEFAULT_SERVER_ENTRY;
|
|
30
32
|
return (source.includes(entryServer) ||
|
|
31
33
|
// TODO update this after handleEvent is replaced with handleRequest
|
|
32
|
-
/(handle-worker-event|index|entry-server)\.js/.test(importer)
|
|
34
|
+
/(handle-worker-event|index|entry-server)\.js/.test(importer) ||
|
|
35
|
+
// Support importing server components for testing
|
|
36
|
+
// TODO: revisit this when RSC splits into two bundles
|
|
37
|
+
/\.test\.[tj]sx?$/.test(importer));
|
|
33
38
|
},
|
|
34
39
|
}),
|
|
35
40
|
platformEntry(),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default function cssModulesRsc() {
|
|
2
|
+
// 1. Original CSS module: `.myStyle { color: red; }`
|
|
3
|
+
// 2. CSS module after 'pre' Vite transforms: `.myStyle_hashedXYZ { color: red; }`
|
|
4
|
+
// 3. CSS module after 'post' Vite transforms: `export const myStyle = 'myStyle_hashedXYZ';`
|
|
5
|
+
let cssMap = new Map();
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
name: 'css-modules-rsc',
|
|
9
|
+
configResolved() {
|
|
10
|
+
cssMap = new Map();
|
|
11
|
+
},
|
|
12
|
+
transform(code, id) {
|
|
13
|
+
if (/\.module\.(s?css|sass|less)/.test(id)) {
|
|
14
|
+
cssMap.set(id, code);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'css-modules-rsc-post',
|
|
20
|
+
enforce: 'post',
|
|
21
|
+
transform(code, id) {
|
|
22
|
+
if (id.includes('.module.') && cssMap.has(id)) {
|
|
23
|
+
return code.replace(/export default .*$/gms, `import React from 'react'; export const StyleTag = () => React.createElement('style', {}, \`${cssMap.get(id)}\`);`);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
}
|
|
@@ -1,85 +1,71 @@
|
|
|
1
1
|
export default () => {
|
|
2
2
|
return {
|
|
3
3
|
name: 'vite-plugin-hydrogen-config',
|
|
4
|
-
config: async (config, env) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
config: async (config, env) => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
return ({
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: {
|
|
9
|
+
// This library is currently included as a compiled vendor lib, not published yet to NPM
|
|
10
|
+
'react-server-dom-vite/client-proxy': require.resolve('@shopify/hydrogen/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js'),
|
|
11
|
+
},
|
|
9
12
|
},
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sourcemap: true,
|
|
14
|
-
/**
|
|
15
|
-
* By default, SSR dedupe logic gets bundled which runs `require('module')`.
|
|
16
|
-
* We don't want this in our workers runtime, because `require` is not supported.
|
|
17
|
-
*/
|
|
18
|
-
rollupOptions: process.env.WORKER
|
|
19
|
-
? {
|
|
20
|
-
output: {
|
|
21
|
-
format: 'es',
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
: {},
|
|
25
|
-
},
|
|
26
|
-
ssr: {
|
|
27
|
-
external: ['isomorphic-dompurify'],
|
|
28
|
-
/**
|
|
29
|
-
* Tell Vite to bundle everything when we're building for Workers.
|
|
30
|
-
* Otherwise, bundle RSC plugin as a workaround to apply the vendor alias above.
|
|
31
|
-
*/
|
|
32
|
-
noExternal: Boolean(process.env.WORKER) || [/react-server-dom-vite/],
|
|
33
|
-
target: process.env.WORKER ? 'webworker' : 'node',
|
|
34
|
-
},
|
|
35
|
-
// Reload when updating local Hydrogen lib
|
|
36
|
-
server: process.env.LOCAL_DEV && {
|
|
37
|
-
watch: {
|
|
38
|
-
ignored: ['!**/node_modules/@shopify/hydrogen/**'],
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
optimizeDeps: {
|
|
42
|
-
exclude: ['@shopify/hydrogen/client', '@shopify/hydrogen/entry-client'],
|
|
43
|
-
include: [
|
|
13
|
+
build: {
|
|
14
|
+
minify: (_b = (_a = config.build) === null || _a === void 0 ? void 0 : _a.minify) !== null && _b !== void 0 ? _b : 'esbuild',
|
|
15
|
+
sourcemap: true,
|
|
44
16
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* server versions and optimize them for ESM.
|
|
17
|
+
* By default, SSR dedupe logic gets bundled which runs `require('module')`.
|
|
18
|
+
* We don't want this in our workers runtime, because `require` is not supported.
|
|
48
19
|
*/
|
|
49
|
-
|
|
20
|
+
rollupOptions: process.env.WORKER
|
|
21
|
+
? {
|
|
22
|
+
output: {
|
|
23
|
+
format: 'es',
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
: {},
|
|
27
|
+
},
|
|
28
|
+
ssr: {
|
|
50
29
|
/**
|
|
51
|
-
* Vite
|
|
52
|
-
*
|
|
53
|
-
* at server start to avoid posterior page reloads and issues (#429 #430).
|
|
30
|
+
* Tell Vite to bundle everything when we're building for Workers.
|
|
31
|
+
* Otherwise, bundle RSC plugin as a workaround to apply the vendor alias above.
|
|
54
32
|
*/
|
|
55
|
-
|
|
56
|
-
'
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
33
|
+
noExternal: Boolean(process.env.WORKER) || [/react-server-dom-vite/],
|
|
34
|
+
target: process.env.WORKER ? 'webworker' : 'node',
|
|
35
|
+
},
|
|
36
|
+
// Reload when updating local Hydrogen lib
|
|
37
|
+
server: process.env.LOCAL_DEV && {
|
|
38
|
+
watch: {
|
|
39
|
+
ignored: ['!**/node_modules/@shopify/hydrogen/**'],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
optimizeDeps: {
|
|
43
|
+
exclude: ['@shopify/hydrogen/client', '@shopify/hydrogen/entry-client'],
|
|
44
|
+
include: [
|
|
45
|
+
/**
|
|
46
|
+
* Additionally, the following dependencies have trouble loading the
|
|
47
|
+
* correct version of the dependency (server vs client). This tells Vite to take the
|
|
48
|
+
* server versions and optimize them for ESM.
|
|
49
|
+
*/
|
|
50
|
+
'react-helmet-async',
|
|
51
|
+
'react-error-boundary',
|
|
52
|
+
/**
|
|
53
|
+
* Vite cannot find the following dependencies since they might be
|
|
54
|
+
* required in RSC asynchronously. This tells Vite to optimize them
|
|
55
|
+
* at server start to avoid posterior page reloads and issues (#429 #430).
|
|
56
|
+
*/
|
|
57
|
+
'react',
|
|
58
|
+
'react-dom/client',
|
|
59
|
+
'react-server-dom-vite/client-proxy',
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
define: {
|
|
63
|
+
__DEV__: env.mode !== 'production',
|
|
64
|
+
__WORKER__: !!process.env.WORKER,
|
|
65
|
+
},
|
|
66
|
+
envPrefix: ['VITE_', 'PUBLIC_'],
|
|
67
|
+
base: process.env.HYDROGEN_ASSET_BASE_URL,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
84
70
|
};
|
|
85
71
|
};
|
|
@@ -61,7 +61,7 @@ export default () => {
|
|
|
61
61
|
const packageJson = {
|
|
62
62
|
type: isESM ? 'module' : 'commonjs',
|
|
63
63
|
main: mainFile,
|
|
64
|
-
exports: { '.': mainFile, mainFile },
|
|
64
|
+
exports: { '.': mainFile, [mainFile]: mainFile },
|
|
65
65
|
};
|
|
66
66
|
fs.writeFileSync(path.join(options.dir, 'package.json'), JSON.stringify(packageJson, null, 2), 'utf-8');
|
|
67
67
|
}
|