@shopify/hydrogen 0.6.2 → 0.7.1
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/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/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/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 +1 -1
- package/dist/esnext/components/Video/Video.d.ts +1 -1
- package/dist/esnext/components/index.d.ts +2 -2
- package/dist/esnext/entry-server.js +43 -19
- 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.js +1 -1
- package/dist/esnext/{hooks → foundation}/useQuery/QueryProvider.d.ts +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/QueryProvider.js +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/hooks.d.ts +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/hooks.js +13 -3
- package/dist/esnext/{hooks → foundation}/useQuery/index.d.ts +0 -0
- package/dist/esnext/{hooks → foundation}/useQuery/index.js +0 -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/client-imports.d.ts +1 -1
- package/dist/esnext/framework/Hydration/client-imports.js +1 -1
- package/dist/esnext/framework/Hydration/wire.server.js +1 -1
- package/dist/esnext/framework/Hydration/writer.server.js +1 -0
- 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 +4 -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 +11 -9
- 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.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 +6 -3
- package/dist/esnext/types.d.ts +19 -3
- 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/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/client-imports.d.ts +1 -1
- package/dist/node/framework/Hydration/client-imports.js +2 -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.js +3 -3
- 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 +4 -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 +12 -10
- package/dist/node/framework/server-components.js +27 -49
- package/dist/node/handle-event.js +12 -8
- package/dist/node/types.d.ts +19 -3
- 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/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/handle-event.js +8 -4
- package/dist/worker/types.d.ts +19 -3
- package/package.json +9 -7
|
@@ -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
|
]);
|
|
@@ -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";
|
|
@@ -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
|
}
|
|
@@ -23,4 +23,4 @@ export declare function UnitPrice<TTag extends ElementType>(props: Props<TTag> &
|
|
|
23
23
|
export declare namespace UnitPrice {
|
|
24
24
|
var Fragment: string;
|
|
25
25
|
}
|
|
26
|
-
export declare const UnitPriceFragment
|
|
26
|
+
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}";
|
|
@@ -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';
|
|
@@ -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) {
|
|
@@ -180,7 +175,7 @@ function buildReactApp({ App, state, context, request, dev, }) {
|
|
|
180
175
|
const componentResponse = new ServerComponentResponse();
|
|
181
176
|
const ReactApp = (props) => (React.createElement(StaticRouter, { location: { pathname: state.pathname, search: state.search }, context: context },
|
|
182
177
|
React.createElement(HelmetProvider, { context: helmetContext },
|
|
183
|
-
React.createElement(App, { request: request, response: componentResponse
|
|
178
|
+
React.createElement(App, { ...props, request: request, response: componentResponse }))));
|
|
184
179
|
return { helmetContext, ReactApp, componentResponse };
|
|
185
180
|
}
|
|
186
181
|
function extractHeadElements(helmetContext) {
|
|
@@ -310,3 +305,32 @@ async function renderAppFromStringWithPrepass(ReactApp, state, isReactHydrationR
|
|
|
310
305
|
: body;
|
|
311
306
|
}
|
|
312
307
|
export default renderHydrogen;
|
|
308
|
+
function startWritingHtmlToServerResponse(response, startWriting, error) {
|
|
309
|
+
if (!response.headersSent) {
|
|
310
|
+
response.setHeader('Content-type', 'text/html');
|
|
311
|
+
response.write('<!DOCTYPE html>');
|
|
312
|
+
}
|
|
313
|
+
startWriting();
|
|
314
|
+
if (error) {
|
|
315
|
+
// This error was delayed until the headers were properly sent.
|
|
316
|
+
response.write(getErrorMarkup(error));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function writeHeadToServerResponse(response, { headers, status, customStatus }, error) {
|
|
320
|
+
var _a, _b;
|
|
321
|
+
if (response.headersSent)
|
|
322
|
+
return;
|
|
323
|
+
headers.forEach((value, key) => response.setHeader(key, value));
|
|
324
|
+
if (error) {
|
|
325
|
+
response.statusCode = 500;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
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;
|
|
329
|
+
if (customStatus === null || customStatus === void 0 ? void 0 : customStatus.text) {
|
|
330
|
+
response.statusMessage = customStatus.text;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function isRedirect(response) {
|
|
335
|
+
return response.statusCode >= 300 && response.statusCode < 400;
|
|
336
|
+
}
|
|
@@ -7,12 +7,14 @@ import { useServerState } from '../useServerState';
|
|
|
7
7
|
* server state, which in turn fetches the correct server component.
|
|
8
8
|
*/
|
|
9
9
|
export function ServerStateRouter() {
|
|
10
|
-
const { setServerState, pending } = useServerState();
|
|
10
|
+
const { setServerState, pending, serverState } = useServerState();
|
|
11
11
|
const [isNavigating, setIsNavigating] = useState(false);
|
|
12
12
|
const location = useLocation();
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (serverState.pathname !== location.pathname) {
|
|
15
|
+
setIsNavigating(true);
|
|
16
|
+
setServerState('pathname', location.pathname);
|
|
17
|
+
}
|
|
16
18
|
}, [location.pathname, setServerState]);
|
|
17
19
|
useEffect(() => {
|
|
18
20
|
/**
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
+
declare global {
|
|
3
|
+
var __DEV__: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ServerState {
|
|
6
|
+
pathname: string;
|
|
7
|
+
search: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface ServerStateSetter {
|
|
11
|
+
(input: ((prev: ServerState) => Partial<ServerState>) | Partial<ServerState> | string, propValue?: any): void;
|
|
12
|
+
}
|
|
2
13
|
export interface ServerStateContextValue {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
pending: boolean;
|
|
15
|
+
serverState: ServerState;
|
|
16
|
+
setServerState: ServerStateSetter;
|
|
6
17
|
}
|
|
7
|
-
export declare const ServerStateContext: React.Context<
|
|
8
|
-
interface
|
|
9
|
-
serverState:
|
|
10
|
-
setServerState: React.Dispatch<React.SetStateAction<
|
|
11
|
-
pathname: string;
|
|
12
|
-
search: string;
|
|
13
|
-
}>>;
|
|
18
|
+
export declare const ServerStateContext: React.Context<ServerStateContextValue>;
|
|
19
|
+
interface ServerStateProviderProps {
|
|
20
|
+
serverState: ServerState;
|
|
21
|
+
setServerState: React.Dispatch<React.SetStateAction<ServerState>>;
|
|
14
22
|
children: ReactNode;
|
|
15
23
|
}
|
|
16
|
-
export declare function ServerStateProvider({ serverState, setServerState, children, }:
|
|
24
|
+
export declare function ServerStateProvider({ serverState, setServerState, children, }: ServerStateProviderProps): JSX.Element;
|
|
17
25
|
export {};
|
|
@@ -4,7 +4,7 @@ useTransition, } from 'react';
|
|
|
4
4
|
export const ServerStateContext = createContext(null);
|
|
5
5
|
export function ServerStateProvider({ serverState, setServerState, children, }) {
|
|
6
6
|
const [pending, startTransition] = useTransition();
|
|
7
|
-
const setServerStateCallback = useCallback((input,
|
|
7
|
+
const setServerStateCallback = useCallback((input, propValue) => {
|
|
8
8
|
/**
|
|
9
9
|
* By wrapping this state change in a transition, React renders the new state
|
|
10
10
|
* concurrently in a new "tree" instead of Suspending and showing the (blank)
|
|
@@ -13,26 +13,27 @@ export function ServerStateProvider({ serverState, setServerState, children, })
|
|
|
13
13
|
* the `pending` flag also provided by the hook to display in the UI.
|
|
14
14
|
*/
|
|
15
15
|
startTransition(() => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
return setServerState((prev) => {
|
|
17
|
+
let newValue;
|
|
18
|
+
if (typeof input === 'function') {
|
|
19
|
+
newValue = input(prev);
|
|
20
|
+
}
|
|
21
|
+
else if (typeof input === 'string') {
|
|
22
|
+
newValue = { [input]: propValue };
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
newValue = input;
|
|
26
|
+
}
|
|
27
|
+
if (__DEV__) {
|
|
28
|
+
if ('request' in newValue || 'response' in newValue) {
|
|
29
|
+
console.warn(`Custom "request" and "response" properties in server state are ignored. Use a different name.`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
24
33
|
...prev,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
// Support a key, value as well.
|
|
30
|
-
if (typeof input === 'string') {
|
|
31
|
-
return setServerState((prev) => ({
|
|
32
|
-
...prev,
|
|
33
|
-
[input]: value,
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
34
|
+
...newValue,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
36
37
|
});
|
|
37
38
|
}, [setServerState, startTransition]);
|
|
38
39
|
const value = useMemo(() => ({
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { ServerStateProvider, ServerStateContext,
|
|
1
|
+
export { ServerStateProvider, ServerStateContext, } from './ServerStateProvider.client';
|
|
2
|
+
export type { ServerState, ServerStateContextValue, } from './ServerStateProvider.client';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ShopifyProvider } from './ShopifyProvider';
|
|
3
|
-
import { QueryProvider } from '../../
|
|
3
|
+
import { QueryProvider } from '../../foundation/useQuery';
|
|
4
4
|
export function ShopifyServerProvider({ children, shopifyConfig, hydrationContext, }) {
|
|
5
5
|
return (React.createElement(ShopifyProvider, { shopifyConfig: shopifyConfig },
|
|
6
6
|
React.createElement(QueryProvider, { hydrationContext: hydrationContext }, children)));
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -11,6 +11,16 @@ key,
|
|
|
11
11
|
queryFn,
|
|
12
12
|
/** Options including `cache` to manage the cache behavior of the sub-request. */
|
|
13
13
|
queryOptions) {
|
|
14
|
+
const resolvedQueryOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Prevent react-query from from retrying request failures. This sometimes bites developers
|
|
17
|
+
* because they will get back a 200 GraphQL response with errors, but not properly check
|
|
18
|
+
* for errors. This leads to a failed `queryFn` and react-query keeps running it, leading
|
|
19
|
+
* to a much slower response time and a poor developer experience.
|
|
20
|
+
*/
|
|
21
|
+
retry: false,
|
|
22
|
+
...(queryOptions !== null && queryOptions !== void 0 ? queryOptions : {}),
|
|
23
|
+
};
|
|
14
24
|
/**
|
|
15
25
|
* Attempt to read the query from cache. If it doesn't exist or if it's stale, regenerate it.
|
|
16
26
|
*/
|
|
@@ -35,7 +45,7 @@ queryOptions) {
|
|
|
35
45
|
await setItemInCache(lockKey, true);
|
|
36
46
|
try {
|
|
37
47
|
const output = await generateNewOutput();
|
|
38
|
-
await setItemInCache(key, output,
|
|
48
|
+
await setItemInCache(key, output, resolvedQueryOptions === null || resolvedQueryOptions === void 0 ? void 0 : resolvedQueryOptions.cache);
|
|
39
49
|
}
|
|
40
50
|
catch (e) {
|
|
41
51
|
console.error(`Error generating async response: ${e.message}`);
|
|
@@ -51,8 +61,8 @@ queryOptions) {
|
|
|
51
61
|
/**
|
|
52
62
|
* Important: Do this async
|
|
53
63
|
*/
|
|
54
|
-
runDelayedFunction(async () => await setItemInCache(key, newOutput,
|
|
64
|
+
runDelayedFunction(async () => await setItemInCache(key, newOutput, resolvedQueryOptions === null || resolvedQueryOptions === void 0 ? void 0 : resolvedQueryOptions.cache));
|
|
55
65
|
return newOutput;
|
|
56
66
|
}
|
|
57
|
-
return useReactQuery(key, cachedQueryFn,
|
|
67
|
+
return useReactQuery(key, cachedQueryFn, resolvedQueryOptions);
|
|
58
68
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `useServerState` hook allows you to [manage server state](/
|
|
2
|
+
* The `useServerState` hook allows you to [manage server state](/custom-storefronts/hydrogen/framework/server-state) when using Hydrogen as a React Server Component framework.
|
|
3
3
|
*
|
|
4
4
|
* ## Return value
|
|
5
5
|
*
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
* | `pending` | Whether a [transition is pending](https://github.com/reactwg/react-18/discussions/41). |
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
export declare function useServerState():
|
|
15
|
+
export declare function useServerState(): import("../ServerStateProvider").ServerStateContextValue;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { ServerStateContext } from '../ServerStateProvider';
|
|
3
3
|
/**
|
|
4
|
-
* The `useServerState` hook allows you to [manage server state](/
|
|
4
|
+
* The `useServerState` hook allows you to [manage server state](/custom-storefronts/hydrogen/framework/server-state) when using Hydrogen as a React Server Component framework.
|
|
5
5
|
*
|
|
6
6
|
* ## Return value
|
|
7
7
|
*
|
|
@@ -12,7 +12,6 @@ export function wrapInClientMarker(meta) {
|
|
|
12
12
|
// Use object syntax here to make sure the function name
|
|
13
13
|
// comes from the meta params for better error stacks.
|
|
14
14
|
const wrappedComponent = {
|
|
15
|
-
// eslint-disable-next-line react/display-name
|
|
16
15
|
[name]: (props) => React.createElement(ClientMarker, { ...{ props, meta } }),
|
|
17
16
|
}[name];
|
|
18
17
|
// Relay component properties such as `Image.Fragment`
|