@shopify/hydrogen 0.6.3 → 0.8.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/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +3 -3
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.d.ts +1 -1
- package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +1 -1
- package/dist/esnext/components/CartLineProvider/context.d.ts +3 -3
- package/dist/esnext/components/CartProvider/CartProvider.client.js +0 -1
- package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +1 -1
- package/dist/esnext/components/Image/Image.d.ts +1 -1
- package/dist/esnext/components/LocalizationProvider/index.d.ts +1 -0
- package/dist/esnext/components/LocalizationProvider/index.js +1 -0
- package/dist/esnext/components/MediaFile/MediaFile.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.d.ts +1 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +8 -0
- package/dist/esnext/components/Metafield/MetafieldFragment.d.ts +16 -1
- package/dist/esnext/components/Metafield/components/StarRating/StarRating.d.ts +1 -1
- package/dist/esnext/components/Metafield/index.d.ts +2 -2
- package/dist/esnext/components/Model3D/Model3D.client.d.ts +3 -1
- package/dist/esnext/components/Model3D/Model3D.client.js +1 -1
- package/dist/esnext/components/Money/Money.client.d.ts +1 -1
- package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +1 -3
- package/dist/esnext/components/ProductPrice/ProductPrice.client.js +1 -3
- package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +1 -1
- package/dist/esnext/components/ProductProvider/context.d.ts +2 -2
- package/dist/esnext/components/ProductProvider/types.d.ts +2 -2
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.d.ts +1 -1
- package/dist/esnext/components/SelectedVariantAddToCartButton/SelectedVariantAddToCartButton.client.js +1 -1
- package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +2 -3
- package/dist/esnext/components/UnitPrice/UnitPrice.client.js +1 -2
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/index.d.ts +3 -2
- package/dist/esnext/components/index.js +1 -0
- package/dist/esnext/entry-client.js +4 -6
- package/dist/esnext/entry-server.js +49 -32
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheContext.d.ts +2 -0
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheContext.js +4 -0
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheProvider.d.ts +2 -0
- package/dist/esnext/foundation/RenderCacheProvider/RenderCacheProvider.js +5 -0
- package/dist/esnext/foundation/RenderCacheProvider/hook.d.ts +11 -0
- package/dist/esnext/foundation/RenderCacheProvider/hook.js +34 -0
- package/dist/esnext/foundation/RenderCacheProvider/index.d.ts +1 -0
- package/dist/esnext/foundation/RenderCacheProvider/index.js +1 -0
- package/dist/esnext/foundation/RenderCacheProvider/types.d.ts +11 -0
- package/dist/esnext/foundation/RenderCacheProvider/types.js +1 -0
- package/dist/esnext/foundation/Router/ServerStateRouter.client.js +5 -3
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.d.ts +19 -11
- package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.client.js +21 -20
- package/dist/esnext/foundation/ServerStateProvider/index.d.ts +2 -1
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.d.ts +1 -3
- package/dist/esnext/foundation/ShopifyProvider/ShopifyServerProvider.server.js +2 -4
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +0 -5
- package/dist/esnext/foundation/useQuery/hooks.d.ts +17 -0
- package/dist/esnext/{hooks → foundation}/useQuery/hooks.js +14 -6
- package/dist/esnext/foundation/useQuery/index.d.ts +1 -0
- package/dist/esnext/foundation/useQuery/index.js +1 -0
- package/dist/esnext/foundation/useServerState/use-server-state.d.ts +2 -2
- package/dist/esnext/foundation/useServerState/use-server-state.js +1 -1
- package/dist/esnext/framework/ClientMarker/ClientMarker.js +0 -1
- package/dist/esnext/framework/Hydration/Cache.client.js +3 -1
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
- package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +13 -0
- package/dist/esnext/framework/Hydration/wire.server.js +1 -1
- package/dist/esnext/framework/Hydration/writer.server.js +1 -0
- package/dist/esnext/framework/cache.d.ts +2 -2
- package/dist/esnext/framework/cache.js +1 -1
- package/dist/esnext/framework/middleware.d.ts +5 -1
- package/dist/esnext/framework/middleware.js +12 -8
- package/dist/esnext/framework/plugins/resolver.d.ts +1 -0
- package/dist/esnext/framework/plugins/resolver.js +3 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +15 -1
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +8 -2
- package/dist/esnext/framework/plugins/vite-plugin-react-server-components-shim.js +10 -20
- package/dist/esnext/framework/server-components.js +25 -47
- package/dist/esnext/graphql/graphql-constants.d.ts +74 -37
- package/dist/esnext/graphql/graphql-constants.js +89 -15
- package/dist/esnext/handle-event.d.ts +1 -1
- package/dist/esnext/handle-event.js +8 -4
- package/dist/esnext/hooks/index.d.ts +1 -1
- package/dist/esnext/hooks/index.js +1 -1
- package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +3 -3
- package/dist/esnext/hooks/useMoney/hooks.js +2 -16
- package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +2 -3
- package/dist/esnext/hooks/useProductOptions/types.d.ts +2 -3
- package/dist/esnext/hooks/useShopQuery/hooks.d.ts +4 -2
- package/dist/esnext/hooks/useShopQuery/hooks.js +22 -13
- package/dist/esnext/types.d.ts +21 -4
- package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +0 -7
- package/dist/esnext/utilities/flattenConnection/flattenConnection.js +0 -7
- package/dist/esnext/utilities/isClient/isClient.d.ts +0 -4
- package/dist/esnext/utilities/isClient/isClient.js +0 -4
- package/dist/esnext/utilities/isServer/isServer.d.ts +0 -4
- package/dist/esnext/utilities/isServer/isServer.js +0 -4
- package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +2 -33
- package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -31
- package/dist/esnext/utilities/suspense.d.ts +2 -2
- package/dist/esnext/utilities/suspense.js +0 -6
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/framework/ClientMarker/ClientMarker.js +2 -3
- package/dist/node/framework/Hydration/Cache.client.js +7 -5
- package/dist/node/framework/Hydration/HydrationContext.server.js +1 -1
- package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
- package/dist/node/framework/Hydration/ServerComponentResponse.server.js +15 -2
- package/dist/node/framework/Hydration/react-utils.js +3 -3
- package/dist/node/framework/Hydration/wire.server.js +2 -2
- package/dist/node/framework/Hydration/writer.server.js +1 -0
- package/dist/node/framework/cache.d.ts +2 -2
- package/dist/node/framework/cache.js +5 -4
- package/dist/node/framework/middleware.d.ts +5 -1
- package/dist/node/framework/middleware.js +17 -11
- package/dist/node/framework/plugin.js +5 -5
- package/dist/node/framework/plugins/resolver.d.ts +1 -0
- package/dist/node/framework/plugins/resolver.js +7 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +15 -1
- package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +8 -2
- package/dist/node/framework/plugins/vite-plugin-react-server-components-shim.js +11 -21
- package/dist/node/framework/server-components.js +27 -49
- package/dist/node/handle-event.d.ts +1 -1
- package/dist/node/handle-event.js +12 -8
- package/dist/node/types.d.ts +21 -4
- package/dist/node/utilities/fetch.js +1 -1
- package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +0 -7
- package/dist/node/utilities/flattenConnection/flattenConnection.js +0 -7
- package/dist/node/utilities/isClient/isClient.d.ts +0 -4
- package/dist/node/utilities/isClient/isClient.js +0 -4
- package/dist/node/utilities/isServer/isServer.d.ts +0 -4
- package/dist/node/utilities/isServer/isServer.js +1 -5
- package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +2 -33
- package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -31
- package/dist/node/utilities/suspense.d.ts +2 -2
- package/dist/node/utilities/suspense.js +0 -6
- package/dist/node/utilities/video_parameters.js +1 -1
- package/dist/node/version.d.ts +1 -1
- package/dist/node/version.js +1 -1
- package/dist/worker/framework/Hydration/ServerComponentResponse.server.d.ts +10 -0
- package/dist/worker/framework/Hydration/ServerComponentResponse.server.js +13 -0
- package/dist/worker/framework/cache.d.ts +2 -2
- package/dist/worker/framework/cache.js +1 -1
- package/dist/worker/handle-event.d.ts +1 -1
- package/dist/worker/handle-event.js +8 -4
- package/dist/worker/types.d.ts +21 -4
- package/package.json +11 -9
- package/dist/esnext/hooks/useQuery/QueryProvider.d.ts +0 -6
- package/dist/esnext/hooks/useQuery/QueryProvider.js +0 -13
- package/dist/esnext/hooks/useQuery/hooks.d.ts +0 -15
- package/dist/esnext/hooks/useQuery/index.d.ts +0 -2
- package/dist/esnext/hooks/useQuery/index.js +0 -2
|
@@ -6,7 +6,7 @@ import { useCartLinesAddCallback, useCart, useCartCreateCallback, } from '../Car
|
|
|
6
6
|
*/
|
|
7
7
|
export function AddToCartButton(props) {
|
|
8
8
|
const [addingItem, setAddingItem] = useState(false);
|
|
9
|
-
const {
|
|
9
|
+
const { variantId, quantity = 1, attributes, children, onAdd, accessibleAddingToCartLabel, ...passthroughProps } = props;
|
|
10
10
|
const { status, id } = useCart();
|
|
11
11
|
const createCart = useCartCreateCallback();
|
|
12
12
|
const addLines = useCartLinesAddCallback();
|
|
@@ -23,7 +23,7 @@ export function AddToCartButton(props) {
|
|
|
23
23
|
lines: [
|
|
24
24
|
{
|
|
25
25
|
quantity: quantity,
|
|
26
|
-
merchandiseId:
|
|
26
|
+
merchandiseId: variantId,
|
|
27
27
|
attributes: attributes,
|
|
28
28
|
},
|
|
29
29
|
],
|
|
@@ -33,7 +33,7 @@ export function AddToCartButton(props) {
|
|
|
33
33
|
addLines([
|
|
34
34
|
{
|
|
35
35
|
quantity: quantity,
|
|
36
|
-
merchandiseId:
|
|
36
|
+
merchandiseId: variantId,
|
|
37
37
|
attributes: attributes,
|
|
38
38
|
},
|
|
39
39
|
]);
|
|
@@ -7,7 +7,7 @@ export interface CartEstimatedCostProps {
|
|
|
7
7
|
children?: React.ReactNode;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The `CartEstimatedCost` component renders a `Money` component with the
|
|
11
11
|
* cost associated with the `amountType` prop. If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
12
12
|
* If `children` is a function, then it will pass down the render props provided by the parent component.
|
|
13
13
|
*/
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useCart } from '../CartProvider';
|
|
3
3
|
import { Money } from '../Money';
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
5
|
+
* The `CartEstimatedCost` component renders a `Money` component with the
|
|
6
6
|
* cost associated with the `amountType` prop. If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
7
7
|
* If `children` is a function, then it will pass down the render props provided by the parent component.
|
|
8
8
|
*/
|
|
@@ -6,7 +6,7 @@ export declare const CartLineContext: import("react").Context<({
|
|
|
6
6
|
} & Pick<import("../../graphql/types/types").Attribute, "key" | "value">)[];
|
|
7
7
|
merchandise: {
|
|
8
8
|
__typename?: "ProductVariant" | undefined;
|
|
9
|
-
} & Pick<import("../../graphql/types/types").ProductVariant, "
|
|
9
|
+
} & Pick<import("../../graphql/types/types").ProductVariant, "id" | "title" | "availableForSale" | "requiresShipping"> & {
|
|
10
10
|
compareAtPriceV2?: import("../../graphql/types/types").Maybe<{
|
|
11
11
|
__typename?: "MoneyV2" | undefined;
|
|
12
12
|
} & {
|
|
@@ -21,12 +21,12 @@ export declare const CartLineContext: import("react").Context<({
|
|
|
21
21
|
__typename?: "Image" | undefined;
|
|
22
22
|
} & {
|
|
23
23
|
__typename?: "Image" | undefined;
|
|
24
|
-
} & Pick<import("../../graphql/types/types").Image, "
|
|
24
|
+
} & Pick<import("../../graphql/types/types").Image, "id" | "height" | "width" | "url" | "altText">> | undefined;
|
|
25
25
|
product: {
|
|
26
26
|
__typename?: "Product" | undefined;
|
|
27
27
|
} & Pick<import("../../graphql/types/types").Product, "title" | "handle">;
|
|
28
28
|
selectedOptions: ({
|
|
29
29
|
__typename?: "SelectedOption" | undefined;
|
|
30
|
-
} & Pick<import("../../graphql/types/types").SelectedOption, "
|
|
30
|
+
} & Pick<import("../../graphql/types/types").SelectedOption, "name" | "value">)[];
|
|
31
31
|
};
|
|
32
32
|
}) | null>;
|
|
@@ -417,7 +417,6 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
419
|
buyerIdentityUpdate({ countryCode }, state);
|
|
420
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
421
420
|
}, [countryCode]);
|
|
422
421
|
const cartContextValue = useMemo(() => {
|
|
423
422
|
return {
|
|
@@ -22,5 +22,5 @@ export declare function ExternalVideo<TTag extends React.ElementType = 'iframe'>
|
|
|
22
22
|
export declare namespace ExternalVideo {
|
|
23
23
|
var Fragment: string;
|
|
24
24
|
}
|
|
25
|
-
export declare const ExternalVideoFragment
|
|
25
|
+
export declare const ExternalVideoFragment = "fragment ExternalVideoFragment on ExternalVideo {\n id\n embeddedUrl\n host\n}\n\n";
|
|
26
26
|
export {};
|
|
@@ -38,5 +38,5 @@ export declare function Image<TTag extends React.ElementType = 'img'>(props: Pro
|
|
|
38
38
|
export declare namespace Image {
|
|
39
39
|
var Fragment: string;
|
|
40
40
|
}
|
|
41
|
-
export declare const ImageFragment
|
|
41
|
+
export declare const ImageFragment = "fragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n\n";
|
|
42
42
|
export {};
|
|
@@ -24,5 +24,5 @@ export declare function MediaFile({ media, options, ...passthroughProps }: Media
|
|
|
24
24
|
export declare namespace MediaFile {
|
|
25
25
|
var Fragment: string;
|
|
26
26
|
}
|
|
27
|
-
export declare const MediaFileFragment
|
|
27
|
+
export declare const MediaFileFragment = "\nfragment MediaFileFragment on Media {\n ... on MediaImage {\n mediaContentType\n image {\n ...ImageFragment\n }\n }\n ... on Video {\n mediaContentType\n ...VideoFragment\n }\n ... on ExternalVideo {\n mediaContentType\n ...ExternalVideoFragment\n }\n ... on Model3d {\n mediaContentType\n ...Model3DFragment\n }\n}\n\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n\nfragment VideoFragment on Video {\n id\n previewImage {\n url\n }\n sources {\n mimeType\n url\n }\n}\n\nfragment ExternalVideoFragment on ExternalVideo {\n id\n embeddedUrl\n host\n}\n\nfragment Model3DFragment on Model3d {\n id\n alt\n mediaContentType\n previewImage {\n url\n }\n sources {\n url\n }\n}\n";
|
|
28
28
|
export {};
|
|
@@ -22,4 +22,4 @@ export declare function Metafield<TTag extends ElementType>(props: Props<TTag> &
|
|
|
22
22
|
export declare namespace Metafield {
|
|
23
23
|
var Fragment: string;
|
|
24
24
|
}
|
|
25
|
-
export declare const MetafieldFragment:
|
|
25
|
+
export declare const MetafieldFragment = "\nfragment MetafieldFragment on Metafield {\n id\n type\n namespace\n key\n value\n createdAt\n updatedAt\n description\n reference @include(if: $includeReferenceMetafieldDetails) {\n __typename\n ... on MediaImage {\n id\n mediaContentType\n image {\n ...ImageFragment\n }\n }\n }\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
|
|
@@ -4,6 +4,7 @@ import { getMeasurementAsString } from '../../utilities';
|
|
|
4
4
|
import { StarRating } from './components/StarRating';
|
|
5
5
|
import { RawHtml } from '../RawHtml';
|
|
6
6
|
import { MetafieldFragment as Fragment } from '../../graphql/graphql-constants';
|
|
7
|
+
import { Image } from '../Image';
|
|
7
8
|
/**
|
|
8
9
|
* The `Metafield` component renders the value of a Storefront
|
|
9
10
|
* API's [Metafield object](/api/storefront/reference/common-objects/metafield).
|
|
@@ -16,6 +17,7 @@ import { MetafieldFragment as Fragment } from '../../graphql/graphql-constants';
|
|
|
16
17
|
* Metafield's `value`. For more information, refer to the [Default Output](#default-output) section.
|
|
17
18
|
*/
|
|
18
19
|
export function Metafield(props) {
|
|
20
|
+
var _a;
|
|
19
21
|
const { metafield, children, as, ...passthroughProps } = props;
|
|
20
22
|
const { locale } = useShop();
|
|
21
23
|
if (metafield.value == null) {
|
|
@@ -54,6 +56,12 @@ export function Metafield(props) {
|
|
|
54
56
|
case 'json':
|
|
55
57
|
const Wrapper = as !== null && as !== void 0 ? as : 'span';
|
|
56
58
|
return (React.createElement(Wrapper, { ...passthroughProps }, JSON.stringify(metafield.value)));
|
|
59
|
+
case 'file_reference': {
|
|
60
|
+
if (((_a = metafield.reference) === null || _a === void 0 ? void 0 : _a.__typename) === 'MediaImage') {
|
|
61
|
+
const ref = metafield.reference;
|
|
62
|
+
return ref.image ? (React.createElement(Image, { image: ref.image, ...passthroughProps })) : null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
57
65
|
default: {
|
|
58
66
|
const Wrapper = as !== null && as !== void 0 ? as : 'span';
|
|
59
67
|
return (React.createElement(Wrapper, { ...passthroughProps }, metafield.value.toString()));
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import * as Types from '../../graphql/types/types';
|
|
2
|
+
import { ImageFragmentFragment } from '../Image/ImageFragment';
|
|
2
3
|
export declare type MetafieldFragmentFragment = {
|
|
3
4
|
__typename?: 'Metafield';
|
|
4
|
-
} & Pick<Types.Metafield, 'id' | 'type' | 'namespace' | 'key' | 'value' | 'createdAt' | 'updatedAt' | 'description'
|
|
5
|
+
} & Pick<Types.Metafield, 'id' | 'type' | 'namespace' | 'key' | 'value' | 'createdAt' | 'updatedAt' | 'description'> & {
|
|
6
|
+
reference?: Types.Maybe<({
|
|
7
|
+
__typename: 'MediaImage';
|
|
8
|
+
} & Pick<Types.MediaImage, 'id' | 'mediaContentType'> & {
|
|
9
|
+
image?: Types.Maybe<{
|
|
10
|
+
__typename?: 'Image';
|
|
11
|
+
} & ImageFragmentFragment>;
|
|
12
|
+
}) | {
|
|
13
|
+
__typename: 'Page';
|
|
14
|
+
} | {
|
|
15
|
+
__typename: 'Product';
|
|
16
|
+
} | {
|
|
17
|
+
__typename: 'ProductVariant';
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
@@ -8,5 +8,5 @@ export interface StarRatingProps {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function StarRating<TTag extends ElementType>(props: Props<TTag> & StarRatingProps): JSX.Element;
|
|
10
10
|
export declare function Star({ percentFilled }: {
|
|
11
|
-
percentFilled:
|
|
11
|
+
percentFilled: number;
|
|
12
12
|
}): JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Metafield, MetafieldFragment } from './Metafield.client';
|
|
2
|
-
export { MetafieldType } from './types';
|
|
3
|
-
export { MetafieldFragmentFragment } from './MetafieldFragment';
|
|
2
|
+
export type { MetafieldType } from './types';
|
|
3
|
+
export type { MetafieldFragmentFragment } from './MetafieldFragment';
|
|
@@ -15,6 +15,8 @@ export interface Model3DProps {
|
|
|
15
15
|
};
|
|
16
16
|
/** A string of either `auto`, `lazy`, or `eager` to indicate the conditions for preloading. Refer to [`loading` in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-attributes-loading). */
|
|
17
17
|
loading?: 'auto' | 'lazy' | 'eager';
|
|
18
|
+
/** A url to display an image instead of the model, useful for showing the user something before a model is loaded and ready to render. If none is provided, [Model3d.previewImage](https://shopify.dev/api/storefront/reference/products/model3d#previewimage-2021-10) is used. Refer to [`poster` in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-attributes-poster). */
|
|
19
|
+
poster?: string;
|
|
18
20
|
/** A string of either `auto`, `interaction`, or `manual` to indicate when the model should be revealed. Refer to [`reveal` in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-loading-attributes-reveal). */
|
|
19
21
|
reveal?: 'auto' | 'interaction' | 'manual';
|
|
20
22
|
/** A boolean to enable an AR experience. Refer to [`ar` in the <model-viewer> documentation](https://modelviewer.dev/docs/index.html#entrydocs-augmentedreality-attributes-ar). */
|
|
@@ -132,5 +134,5 @@ export declare function Model3D<TTag extends ElementType>(props: Props<TTag, Pro
|
|
|
132
134
|
export declare namespace Model3D {
|
|
133
135
|
var Fragment: string;
|
|
134
136
|
}
|
|
135
|
-
export declare const Model3DFragment
|
|
137
|
+
export declare const Model3DFragment = "fragment Model3DFragment on Model3d {\n id\n alt\n mediaContentType\n previewImage {\n url\n }\n sources {\n url\n }\n}\n\n";
|
|
136
138
|
export {};
|
|
@@ -109,7 +109,7 @@ export function Model3D(props) {
|
|
|
109
109
|
// TODO: What do we want to display while the model-viewer library loads?
|
|
110
110
|
return null;
|
|
111
111
|
}
|
|
112
|
-
return (React.createElement("model-viewer", { ref: callbackRef, ...passthroughProps, class: className, id: id, src: model.sources[0].url, alt: model.alt, "camera-controls": (_a = passthroughProps.cameraControls) !== null && _a !== void 0 ? _a : true, poster: (_b = model.previewImage) === null || _b === void 0 ? void 0 : _b.url, autoplay: (_c = passthroughProps.autoplay) !== null && _c !== void 0 ? _c : true, loading: passthroughProps.loading, reveal: passthroughProps.reveal, ar: passthroughProps.ar, "ar-modes": passthroughProps.arModes, "ar-scale": passthroughProps.arScale, "ar-placement": passthroughProps.arPlacement, "ios-src": passthroughProps.iosSrc, "touch-action": passthroughProps.touchAction, "disable-zoom": passthroughProps.disableZoom, "orbit-sensitivity": passthroughProps.orbitSensitivity, "auto-rotate": passthroughProps.autoRotate, "auto-rotate-delay": passthroughProps.autoRotateDelay, "rotation-per-second": passthroughProps.rotationPerSecond, "interaction-policy": passthroughProps.interactionPolicy, "interaction-prompt": passthroughProps.interactionPrompt, "interaction-prompt-style": passthroughProps.interactionPromptStyle, "interaction-prompt-threshold": passthroughProps.interactionPromptThreshold, "camera-orbit": passthroughProps.cameraOrbit, "camera-target": passthroughProps.cameraTarget, "field-of-view": passthroughProps.fieldOfView, "max-camera-orbit": passthroughProps.maxCameraOrbit, "min-camera-orbit": passthroughProps.minCameraOrbit, "max-field-of-view": passthroughProps.maxFieldOfView, "min-field-of-view": passthroughProps.minFieldOfView, bounds: passthroughProps.bounds, "interpolation-decay": (_d = passthroughProps.interpolationDecay) !== null && _d !== void 0 ? _d : 100, "skybox-image": passthroughProps.skyboxImage, "environment-image": passthroughProps.environmentImage, exposure: passthroughProps.exposure, "shadow-intensity": (_e = passthroughProps.shadowIntensity) !== null && _e !== void 0 ? _e : 0, "shadow-softness": (_f = passthroughProps.shadowSoftness) !== null && _f !== void 0 ? _f : 0, "animation-name": passthroughProps.animationName, "animation-crossfade-duration": passthroughProps.animationCrossfadeDuration, "variant-name": passthroughProps.variantName, orientation: passthroughProps.orientation, scale: passthroughProps.scale }, children));
|
|
112
|
+
return (React.createElement("model-viewer", { ref: callbackRef, ...passthroughProps, class: className, id: id, src: model.sources[0].url, alt: model.alt, "camera-controls": (_a = passthroughProps.cameraControls) !== null && _a !== void 0 ? _a : true, poster: passthroughProps.poster || ((_b = model.previewImage) === null || _b === void 0 ? void 0 : _b.url), autoplay: (_c = passthroughProps.autoplay) !== null && _c !== void 0 ? _c : true, loading: passthroughProps.loading, reveal: passthroughProps.reveal, ar: passthroughProps.ar, "ar-modes": passthroughProps.arModes, "ar-scale": passthroughProps.arScale, "ar-placement": passthroughProps.arPlacement, "ios-src": passthroughProps.iosSrc, "touch-action": passthroughProps.touchAction, "disable-zoom": passthroughProps.disableZoom, "orbit-sensitivity": passthroughProps.orbitSensitivity, "auto-rotate": passthroughProps.autoRotate, "auto-rotate-delay": passthroughProps.autoRotateDelay, "rotation-per-second": passthroughProps.rotationPerSecond, "interaction-policy": passthroughProps.interactionPolicy, "interaction-prompt": passthroughProps.interactionPrompt, "interaction-prompt-style": passthroughProps.interactionPromptStyle, "interaction-prompt-threshold": passthroughProps.interactionPromptThreshold, "camera-orbit": passthroughProps.cameraOrbit, "camera-target": passthroughProps.cameraTarget, "field-of-view": passthroughProps.fieldOfView, "max-camera-orbit": passthroughProps.maxCameraOrbit, "min-camera-orbit": passthroughProps.minCameraOrbit, "max-field-of-view": passthroughProps.maxFieldOfView, "min-field-of-view": passthroughProps.minFieldOfView, bounds: passthroughProps.bounds, "interpolation-decay": (_d = passthroughProps.interpolationDecay) !== null && _d !== void 0 ? _d : 100, "skybox-image": passthroughProps.skyboxImage, "environment-image": passthroughProps.environmentImage, exposure: passthroughProps.exposure, "shadow-intensity": (_e = passthroughProps.shadowIntensity) !== null && _e !== void 0 ? _e : 0, "shadow-softness": (_f = passthroughProps.shadowSoftness) !== null && _f !== void 0 ? _f : 0, "animation-name": passthroughProps.animationName, "animation-crossfade-duration": passthroughProps.animationCrossfadeDuration, "variant-name": passthroughProps.variantName, orientation: passthroughProps.orientation, scale: passthroughProps.scale }, children));
|
|
113
113
|
}
|
|
114
114
|
Model3D.Fragment = Fragment;
|
|
115
115
|
export const Model3DFragment = Fragment;
|
|
@@ -19,4 +19,4 @@ export declare function Money<TTag extends ElementType>(props: Props<TTag> & Mon
|
|
|
19
19
|
export declare namespace Money {
|
|
20
20
|
var Fragment: string;
|
|
21
21
|
}
|
|
22
|
-
export declare const MoneyFragment
|
|
22
|
+
export declare const MoneyFragment = "fragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\n";
|
|
@@ -8,8 +8,6 @@ export interface ProductPriceProps {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* The `ProductPrice` component renders a `Money` component with the product
|
|
11
|
-
* [`priceRange`](/api/storefront/reference/products/productpricerange)'s `maxVariantPrice`
|
|
12
|
-
* or `minVariantPrice`, for either the regular price or compare at price range.
|
|
13
|
-
* It must be a descendent of the `ProductProvider` component.
|
|
11
|
+
* [`priceRange`](/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range. It must be a descendent of the `ProductProvider` component.
|
|
14
12
|
*/
|
|
15
13
|
export declare function ProductPrice<TTag extends ElementType>(props: Props<TTag> & ProductPriceProps): JSX.Element | null;
|
|
@@ -3,9 +3,7 @@ import { Money } from '../Money';
|
|
|
3
3
|
import { useProduct } from '../ProductProvider';
|
|
4
4
|
/**
|
|
5
5
|
* The `ProductPrice` component renders a `Money` component with the product
|
|
6
|
-
* [`priceRange`](/api/storefront/reference/products/productpricerange)'s `maxVariantPrice`
|
|
7
|
-
* or `minVariantPrice`, for either the regular price or compare at price range.
|
|
8
|
-
* It must be a descendent of the `ProductProvider` component.
|
|
6
|
+
* [`priceRange`](/api/storefront/reference/products/productpricerange)'s `maxVariantPrice` or `minVariantPrice`, for either the regular price or compare at price range. It must be a descendent of the `ProductProvider` component.
|
|
9
7
|
*/
|
|
10
8
|
export function ProductPrice(props) {
|
|
11
9
|
var _a, _b, _c, _d;
|
|
@@ -15,4 +15,4 @@ export declare function ProductProvider({ children, product, initialVariantId, }
|
|
|
15
15
|
export declare namespace ProductProvider {
|
|
16
16
|
var Fragment: string;
|
|
17
17
|
}
|
|
18
|
-
export declare const ProductProviderFragment:
|
|
18
|
+
export declare const ProductProviderFragment = "\nfragment ProductProviderFragment on Product {\n compareAtPriceRange {\n maxVariantPrice {\n ...MoneyFragment\n }\n minVariantPrice {\n ...MoneyFragment\n }\n }\n descriptionHtml\n handle\n id\n media(first: $numProductMedia) {\n edges {\n node {\n ...MediaFileFragment\n }\n }\n }\n metafields(first: $numProductMetafields) {\n edges {\n node {\n ...MetafieldFragment\n }\n }\n }\n priceRange {\n maxVariantPrice {\n ...MoneyFragment\n }\n minVariantPrice {\n ...MoneyFragment\n }\n }\n title\n variants(first: $numProductVariants) {\n edges {\n node {\n ...VariantFragment\n }\n }\n }\n sellingPlanGroups(first: $numProductSellingPlanGroups) {\n edges {\n node {\n ...SellingPlanGroupsFragment\n }\n }\n }\n}\n\n\nfragment MediaFileFragment on Media {\n ... on MediaImage {\n mediaContentType\n image {\n ...ImageFragment\n }\n }\n ... on Video {\n mediaContentType\n ...VideoFragment\n }\n ... on ExternalVideo {\n mediaContentType\n ...ExternalVideoFragment\n }\n ... on Model3d {\n mediaContentType\n ...Model3DFragment\n }\n}\n\n\nfragment MetafieldFragment on Metafield {\n id\n type\n namespace\n key\n value\n createdAt\n updatedAt\n description\n reference @include(if: $includeReferenceMetafieldDetails) {\n __typename\n ... on MediaImage {\n id\n mediaContentType\n image {\n ...ImageFragment\n }\n }\n }\n}\n\nfragment VariantFragment on ProductVariant {\n id\n title\n availableForSale\n image {\n ...ImageFragment\n }\n ...UnitPriceFragment\n priceV2 {\n ...MoneyFragment\n }\n compareAtPriceV2 {\n ...MoneyFragment\n }\n selectedOptions {\n name\n value\n }\n metafields(first: $numProductVariantMetafields) {\n edges {\n node {\n ...MetafieldFragment\n }\n }\n }\n sellingPlanAllocations(first: $numProductVariantSellingPlanAllocations) {\n edges {\n node {\n priceAdjustments {\n compareAtPrice {\n ...MoneyFragment\n }\n perDeliveryPrice {\n ...MoneyFragment\n }\n price {\n ...MoneyFragment\n }\n unitPrice {\n ...MoneyFragment\n }\n }\n sellingPlan {\n ...SellingPlanFragment\n }\n }\n }\n }\n}\n\n\nfragment SellingPlanGroupsFragment on SellingPlanGroup {\n sellingPlans(first:$numProductSellingPlans) {\n edges {\n node {\n ...SellingPlanFragment\n }\n }\n }\n appName\n name\n options {\n name\n values\n }\n}\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n\nfragment VideoFragment on Video {\n id\n previewImage {\n url\n }\n sources {\n mimeType\n url\n }\n}\n\nfragment ExternalVideoFragment on ExternalVideo {\n id\n embeddedUrl\n host\n}\n\nfragment Model3DFragment on Model3d {\n id\n alt\n mediaContentType\n previewImage {\n url\n }\n sources {\n url\n }\n}\n\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n\n\nfragment SellingPlanFragment on SellingPlan {\n id\n description\n name\n options {\n name\n value\n }\n priceAdjustments {\n orderCount\n adjustmentValue {\n ...on SellingPlanFixedAmountPriceAdjustment {\n adjustmentAmount {\n ...MoneyFragment\n }\n }\n ...on SellingPlanFixedPriceAdjustment {\n price {\n ...MoneyFragment\n }\n }\n ...on SellingPlanPercentagePriceAdjustment {\n adjustmentPercentage\n }\n }\n }\n recurringDeliveries\n}\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n\n\nfragment UnitPriceFragment on ProductVariant {\n unitPriceMeasurement {\n measuredType\n quantityUnit\n quantityValue\n referenceUnit\n referenceValue\n }\n unitPrice {\n ...MoneyFragment\n }\n}\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\n\nfragment SellingPlanFragment on SellingPlan {\n id\n description\n name\n options {\n name\n value\n }\n priceAdjustments {\n orderCount\n adjustmentValue {\n ...on SellingPlanFixedAmountPriceAdjustment {\n adjustmentAmount {\n ...MoneyFragment\n }\n }\n ...on SellingPlanFixedPriceAdjustment {\n price {\n ...MoneyFragment\n }\n }\n ...on SellingPlanPercentagePriceAdjustment {\n adjustmentPercentage\n }\n }\n }\n recurringDeliveries\n}\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProductOptionsHookValue } from '../../hooks';
|
|
2
|
-
import { GraphQLConnection, ParsedMetafield } from '../../types';
|
|
2
|
+
import { GraphQLConnection, ParsedMetafield, RawMetafield } from '../../types';
|
|
3
3
|
import { ProductProviderFragmentFragment } from './ProductProviderFragment';
|
|
4
4
|
import { Product } from './types';
|
|
5
5
|
import { Collection, Image } from '../../graphql/types/types';
|
|
@@ -8,7 +8,7 @@ export declare type ProductContextType = Omit<Product, 'media' | 'metafields' |
|
|
|
8
8
|
media?: ProductProviderFragmentFragment['media']['edges'][0]['node'][];
|
|
9
9
|
mediaConnection?: ProductProviderFragmentFragment['media'];
|
|
10
10
|
metafields?: ParsedMetafield[];
|
|
11
|
-
metafieldsConnection?:
|
|
11
|
+
metafieldsConnection?: GraphQLConnection<RawMetafield>;
|
|
12
12
|
images?: Partial<Image>[];
|
|
13
13
|
imagesConnection?: GraphQLConnection<Partial<Image>>;
|
|
14
14
|
collections?: Partial<Collection>[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SellingPlanGroup, Variant } from '../../hooks/useProductOptions';
|
|
2
|
-
import { GraphQLConnection } from '../../types';
|
|
2
|
+
import { GraphQLConnection, RawMetafield } from '../../types';
|
|
3
3
|
import { ProductProviderFragmentFragment } from './ProductProviderFragment';
|
|
4
4
|
import { ImageFragmentFragment } from '../Image/ImageFragment';
|
|
5
5
|
import { Collection } from '../../graphql/types/types';
|
|
@@ -9,7 +9,7 @@ export interface Product {
|
|
|
9
9
|
handle?: ProductProviderFragmentFragment['descriptionHtml'];
|
|
10
10
|
id?: ProductProviderFragmentFragment['id'];
|
|
11
11
|
media?: ProductProviderFragmentFragment['media'];
|
|
12
|
-
metafields?:
|
|
12
|
+
metafields?: GraphQLConnection<RawMetafield>;
|
|
13
13
|
priceRange?: Partial<ProductProviderFragmentFragment['priceRange']>;
|
|
14
14
|
title?: ProductProviderFragmentFragment['title'];
|
|
15
15
|
variants?: GraphQLConnection<Variant>;
|
|
@@ -7,5 +7,5 @@ declare type PropsWeControl = 'disabled';
|
|
|
7
7
|
* selected variant. Clicking this button automatically adds the selected variant to the cart.
|
|
8
8
|
* It must be a descendent of a `ProductProvider` and `CartProvider` component.
|
|
9
9
|
*/
|
|
10
|
-
export declare function SelectedVariantAddToCartButton<TTag extends React.ElementType = 'button'>(props: Props<TTag, PropsWeControl> & Omit<AddToCartButtonProps, '
|
|
10
|
+
export declare function SelectedVariantAddToCartButton<TTag extends React.ElementType = 'button'>(props: Props<TTag, PropsWeControl> & Omit<AddToCartButtonProps, 'variantId'>): JSX.Element;
|
|
11
11
|
export {};
|
|
@@ -13,5 +13,5 @@ export function SelectedVariantAddToCartButton(props) {
|
|
|
13
13
|
throw new Error('Expected a Product context, but none was found');
|
|
14
14
|
}
|
|
15
15
|
const { children, quantity, attributes, ...passthroughProps } = props;
|
|
16
|
-
return (React.createElement(CartButton, { ...passthroughProps,
|
|
16
|
+
return (React.createElement(CartButton, { ...passthroughProps, variantId: (_b = (_a = product.selectedVariant) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : '', quantity: quantity !== null && quantity !== void 0 ? quantity : 1, disabled: !product.selectedVariant || passthroughProps.disabled, attributes: attributes }, children));
|
|
17
17
|
}
|
|
@@ -13,8 +13,7 @@ export interface UnitPriceProps {
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* The `UnitPrice` component renders a string with a [UnitPrice](/themes/pricing-payments/unit-pricing) as the
|
|
16
|
-
* [Storefront API's `MoneyV2` object](/api/storefront/reference/common-objects/moneyv2) with a reference unit from
|
|
17
|
-
* the [Storefront API's `UnitPriceMeasurement` object](/api/storefront/reference/products/unitpricemeasurement).
|
|
16
|
+
* [Storefront API's `MoneyV2` object](/api/storefront/reference/common-objects/moneyv2) with a reference unit from the [Storefront API's `UnitPriceMeasurement` object](/api/storefront/reference/products/unitpricemeasurement).
|
|
18
17
|
*
|
|
19
18
|
* If `children` is a function, then it will provide render props for the `children` corresponding to the object
|
|
20
19
|
* returned by the `useMoney` hook and the `UnitPriceMeasurement` object.
|
|
@@ -23,4 +22,4 @@ export declare function UnitPrice<TTag extends ElementType>(props: Props<TTag> &
|
|
|
23
22
|
export declare namespace UnitPrice {
|
|
24
23
|
var Fragment: string;
|
|
25
24
|
}
|
|
26
|
-
export declare const UnitPriceFragment
|
|
25
|
+
export declare const UnitPriceFragment = "\nfragment UnitPriceFragment on ProductVariant {\n unitPriceMeasurement {\n measuredType\n quantityUnit\n quantityValue\n referenceUnit\n referenceValue\n }\n unitPrice {\n ...MoneyFragment\n }\n}\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}";
|
|
@@ -4,8 +4,7 @@ import { Money } from '../Money';
|
|
|
4
4
|
import { UnitPriceFragment as Fragment } from '../../graphql/graphql-constants';
|
|
5
5
|
/**
|
|
6
6
|
* The `UnitPrice` component renders a string with a [UnitPrice](/themes/pricing-payments/unit-pricing) as the
|
|
7
|
-
* [Storefront API's `MoneyV2` object](/api/storefront/reference/common-objects/moneyv2) with a reference unit from
|
|
8
|
-
* the [Storefront API's `UnitPriceMeasurement` object](/api/storefront/reference/products/unitpricemeasurement).
|
|
7
|
+
* [Storefront API's `MoneyV2` object](/api/storefront/reference/common-objects/moneyv2) with a reference unit from the [Storefront API's `UnitPriceMeasurement` object](/api/storefront/reference/products/unitpricemeasurement).
|
|
9
8
|
*
|
|
10
9
|
* If `children` is a function, then it will provide render props for the `children` corresponding to the object
|
|
11
10
|
* returned by the `useMoney` hook and the `UnitPriceMeasurement` object.
|
|
@@ -19,4 +19,4 @@ export declare function Video<TTag extends React.ElementType = 'video'>(props: P
|
|
|
19
19
|
export declare namespace Video {
|
|
20
20
|
var Fragment: string;
|
|
21
21
|
}
|
|
22
|
-
export declare const VideoFragment
|
|
22
|
+
export declare const VideoFragment = "fragment VideoFragment on Video {\n id\n previewImage {\n url\n }\n sources {\n mimeType\n url\n }\n}\n\n";
|
|
@@ -15,8 +15,8 @@ export type { Model3DProps } from './Model3D';
|
|
|
15
15
|
export { Model3D } from './Model3D';
|
|
16
16
|
export type { MoneyProps } from './Money';
|
|
17
17
|
export { Money } from './Money';
|
|
18
|
-
export { Metafield
|
|
19
|
-
export type { MetafieldType } from './Metafield';
|
|
18
|
+
export { Metafield } from './Metafield';
|
|
19
|
+
export type { MetafieldType, MetafieldFragmentFragment } from './Metafield';
|
|
20
20
|
export { CartLineProvider, useCartLine } from './CartLineProvider';
|
|
21
21
|
export { CartLineImage } from './CartLineImage';
|
|
22
22
|
export { CartLinePrice } from './CartLinePrice';
|
|
@@ -28,6 +28,7 @@ export { CartLines } from './CartLines';
|
|
|
28
28
|
export { CartCheckoutButton } from './CartCheckoutButton';
|
|
29
29
|
export { CartShopPayButton } from './CartShopPayButton';
|
|
30
30
|
export { CartEstimatedCost } from './CartEstimatedCost';
|
|
31
|
+
export { CartLineSelectedOptions } from './CartLineSelectedOptions';
|
|
31
32
|
export { CartProvider, useCart, useCartAttributesUpdateCallback, useCartBuyerIdentityUpdateCallback, useCartNoteUpdateCallback, useCartCheckoutUrl, useCartCreateCallback, useCartDiscountCodesUpdateCallback, useCartFetch, useCartLinesAddCallback, useCartLinesRemoveCallback, useCartLinesTotalQuantity, useCartLinesUpdateCallback, useInstantCheckout, } from './CartProvider';
|
|
32
33
|
export type { State, Status, Cart, CartWithActions, CartAction, } from './CartProvider';
|
|
33
34
|
export { ProductProvider, useProduct, ProductProviderFragment, } from './ProductProvider';
|
|
@@ -19,6 +19,7 @@ export { CartLines } from './CartLines';
|
|
|
19
19
|
export { CartCheckoutButton } from './CartCheckoutButton';
|
|
20
20
|
export { CartShopPayButton } from './CartShopPayButton';
|
|
21
21
|
export { CartEstimatedCost } from './CartEstimatedCost';
|
|
22
|
+
export { CartLineSelectedOptions } from './CartLineSelectedOptions';
|
|
22
23
|
export { CartProvider, useCart, useCartAttributesUpdateCallback, useCartBuyerIdentityUpdateCallback, useCartNoteUpdateCallback, useCartCheckoutUrl, useCartCreateCallback, useCartDiscountCodesUpdateCallback, useCartFetch, useCartLinesAddCallback, useCartLinesRemoveCallback, useCartLinesTotalQuantity, useCartLinesUpdateCallback, useInstantCheckout, } from './CartProvider';
|
|
23
24
|
export { ProductProvider, useProduct, ProductProviderFragment, } from './ProductProvider';
|
|
24
25
|
export { ProductDescription } from './ProductDescription';
|
|
@@ -6,7 +6,6 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|
|
6
6
|
import { HelmetProvider } from 'react-helmet-async';
|
|
7
7
|
import { useServerResponse } from './framework/Hydration/Cache.client';
|
|
8
8
|
import { ServerStateProvider, ServerStateRouter } from './client';
|
|
9
|
-
import { QueryProvider } from './hooks';
|
|
10
9
|
const renderHydrogen = async (ClientWrapper) => {
|
|
11
10
|
const root = document.getElementById('root');
|
|
12
11
|
if (!root) {
|
|
@@ -25,11 +24,10 @@ function Content({ clientWrapper: ClientWrapper }) {
|
|
|
25
24
|
});
|
|
26
25
|
const response = useServerResponse(serverState);
|
|
27
26
|
return (React.createElement(ServerStateProvider, { serverState: serverState, setServerState: setServerState },
|
|
28
|
-
React.createElement(
|
|
29
|
-
React.createElement(
|
|
30
|
-
React.createElement(
|
|
31
|
-
|
|
32
|
-
React.createElement(ClientWrapper, null, response.read()))))));
|
|
27
|
+
React.createElement(HelmetProvider, null,
|
|
28
|
+
React.createElement(BrowserRouter, null,
|
|
29
|
+
React.createElement(ServerStateRouter, null),
|
|
30
|
+
React.createElement(ClientWrapper, null, response.read())))));
|
|
33
31
|
}
|
|
34
32
|
function Error({ error }) {
|
|
35
33
|
return (React.createElement("div", { style: { padding: '1em' } },
|
|
@@ -12,8 +12,8 @@ import { HelmetProvider } from 'react-helmet-async';
|
|
|
12
12
|
import { Html } from './framework/Hydration/Html';
|
|
13
13
|
import { HydrationWriter } from './framework/Hydration/writer.server';
|
|
14
14
|
import { ServerComponentResponse } from './framework/Hydration/ServerComponentResponse.server';
|
|
15
|
-
import { dehydrate } from 'react-query/hydration';
|
|
16
15
|
import { getCacheControlHeader } from './framework/cache';
|
|
16
|
+
import { RenderCacheProvider } from './foundation/RenderCacheProvider';
|
|
17
17
|
/**
|
|
18
18
|
* react-dom/unstable-fizz provides different entrypoints based on runtime:
|
|
19
19
|
* - `renderToReadableStream` for "browser" (aka worker)
|
|
@@ -84,26 +84,23 @@ const renderHydrogen = (App, hook) => {
|
|
|
84
84
|
* additional checks downstream?
|
|
85
85
|
*/
|
|
86
86
|
response.setHeader(getCacheControlHeader({ dev }), componentResponse.cacheControlHeader);
|
|
87
|
+
writeHeadToServerResponse(response, componentResponse, didError);
|
|
88
|
+
if (isRedirect(response)) {
|
|
89
|
+
// Return redirects early without further rendering/streaming
|
|
90
|
+
return response.end();
|
|
91
|
+
}
|
|
87
92
|
if (!componentResponse.canStream())
|
|
88
93
|
return;
|
|
89
|
-
response
|
|
90
|
-
response.setHeader('Content-type', 'text/html');
|
|
91
|
-
response.write('<!DOCTYPE html>');
|
|
92
|
-
startWriting();
|
|
93
|
-
if (dev && didError) {
|
|
94
|
-
// This error was delayed until the headers were properly sent.
|
|
95
|
-
response.write(getErrorMarkup(didError));
|
|
96
|
-
}
|
|
94
|
+
startWritingHtmlToServerResponse(response, startWriting, dev ? didError : undefined);
|
|
97
95
|
},
|
|
98
96
|
onCompleteAll() {
|
|
99
|
-
|
|
100
|
-
if (componentResponse.canStream())
|
|
97
|
+
if (componentResponse.canStream() || response.writableEnded)
|
|
101
98
|
return;
|
|
102
|
-
response
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
response.
|
|
106
|
-
}
|
|
99
|
+
writeHeadToServerResponse(response, componentResponse, didError);
|
|
100
|
+
if (isRedirect(response)) {
|
|
101
|
+
// Redirects found after any async code
|
|
102
|
+
return response.end();
|
|
103
|
+
}
|
|
107
104
|
if (componentResponse.customBody) {
|
|
108
105
|
if (componentResponse.customBody instanceof Promise) {
|
|
109
106
|
componentResponse.customBody.then((body) => response.end(body));
|
|
@@ -113,9 +110,7 @@ const renderHydrogen = (App, hook) => {
|
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
112
|
else {
|
|
116
|
-
response
|
|
117
|
-
response.write('<!DOCTYPE html>');
|
|
118
|
-
startWriting();
|
|
113
|
+
startWritingHtmlToServerResponse(response, startWriting, dev ? didError : undefined);
|
|
119
114
|
}
|
|
120
115
|
},
|
|
121
116
|
onError(error) {
|
|
@@ -178,9 +173,11 @@ const renderHydrogen = (App, hook) => {
|
|
|
178
173
|
function buildReactApp({ App, state, context, request, dev, }) {
|
|
179
174
|
const helmetContext = {};
|
|
180
175
|
const componentResponse = new ServerComponentResponse();
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
176
|
+
const renderCache = {};
|
|
177
|
+
const ReactApp = (props) => (React.createElement(RenderCacheProvider, { cache: renderCache },
|
|
178
|
+
React.createElement(StaticRouter, { location: { pathname: state.pathname, search: state.search }, context: context },
|
|
179
|
+
React.createElement(HelmetProvider, { context: helmetContext },
|
|
180
|
+
React.createElement(App, { ...props, request: request, response: componentResponse })))));
|
|
184
181
|
return { helmetContext, ReactApp, componentResponse };
|
|
185
182
|
}
|
|
186
183
|
function extractHeadElements(helmetContext) {
|
|
@@ -292,21 +289,41 @@ function renderAppFromBufferedStream(app, isReactHydrationRequest) {
|
|
|
292
289
|
* the results in a context object, and re-render.
|
|
293
290
|
*/
|
|
294
291
|
async function renderAppFromStringWithPrepass(ReactApp, state, isReactHydrationRequest) {
|
|
295
|
-
const hydrationContext = {};
|
|
296
292
|
const app = isReactHydrationRequest ? (React.createElement(HydrationContext.Provider, { value: true },
|
|
297
|
-
React.createElement(ReactApp, {
|
|
293
|
+
React.createElement(ReactApp, { ...state }))) : (React.createElement(ReactApp, { ...state }));
|
|
298
294
|
await ssrPrepass(app);
|
|
299
|
-
/**
|
|
300
|
-
* Dehydrate all the queries made during the prepass above and store
|
|
301
|
-
* them in the context object to be used for the next render pass.
|
|
302
|
-
* This prevents rendering the Suspense fallback in `renderToString`.
|
|
303
|
-
*/
|
|
304
|
-
if (hydrationContext.queryClient) {
|
|
305
|
-
hydrationContext.dehydratedState = dehydrate(hydrationContext.queryClient);
|
|
306
|
-
}
|
|
307
295
|
const body = renderToString(app);
|
|
308
296
|
return isReactHydrationRequest
|
|
309
297
|
? generateWireSyntaxFromRenderedHtml(body)
|
|
310
298
|
: body;
|
|
311
299
|
}
|
|
312
300
|
export default renderHydrogen;
|
|
301
|
+
function startWritingHtmlToServerResponse(response, startWriting, error) {
|
|
302
|
+
if (!response.headersSent) {
|
|
303
|
+
response.setHeader('Content-type', 'text/html');
|
|
304
|
+
response.write('<!DOCTYPE html>');
|
|
305
|
+
}
|
|
306
|
+
startWriting();
|
|
307
|
+
if (error) {
|
|
308
|
+
// This error was delayed until the headers were properly sent.
|
|
309
|
+
response.write(getErrorMarkup(error));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function writeHeadToServerResponse(response, { headers, status, customStatus }, error) {
|
|
313
|
+
var _a, _b;
|
|
314
|
+
if (response.headersSent)
|
|
315
|
+
return;
|
|
316
|
+
headers.forEach((value, key) => response.setHeader(key, value));
|
|
317
|
+
if (error) {
|
|
318
|
+
response.statusCode = 500;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
response.statusCode = (_b = (_a = customStatus === null || customStatus === void 0 ? void 0 : customStatus.code) !== null && _a !== void 0 ? _a : status) !== null && _b !== void 0 ? _b : 200;
|
|
322
|
+
if (customStatus === null || customStatus === void 0 ? void 0 : customStatus.text) {
|
|
323
|
+
response.statusMessage = customStatus.text;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function isRedirect(response) {
|
|
328
|
+
return response.statusCode >= 300 && response.statusCode < 400;
|
|
329
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { QueryKey } from '../../types';
|
|
2
|
+
import type { RenderCacheProviderProps, RenderCacheResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the unique identifier for the current rendering request
|
|
5
|
+
*/
|
|
6
|
+
export declare function useRenderCache(): RenderCacheProviderProps;
|
|
7
|
+
/**
|
|
8
|
+
* Returns data stored in the render cache
|
|
9
|
+
* It will throw the promise if data is not ready
|
|
10
|
+
*/
|
|
11
|
+
export declare function useRenderCacheData<T>(key: QueryKey, fetcher: () => Promise<T>): RenderCacheResult<T>;
|