@gem-sdk/core 1.10.15 → 1.10.16
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.
|
@@ -340,10 +340,15 @@ const createBuilderPreviewProvider = (args)=>zustand.createStore((set, get)=>({
|
|
|
340
340
|
}));
|
|
341
341
|
const BuilderPreviewProvider = ({ children , state , lazy , ...passProps })=>{
|
|
342
342
|
const Component = lazy ? react.Suspense : react.Fragment;
|
|
343
|
+
const value = react.useMemo(()=>{
|
|
344
|
+
return createBuilderPreviewProvider(state);
|
|
345
|
+
}, [
|
|
346
|
+
state
|
|
347
|
+
]);
|
|
343
348
|
return /*#__PURE__*/ jsxRuntime.jsx(Component, {
|
|
344
349
|
children: /*#__PURE__*/ jsxRuntime.jsx(BuilderPreviewContext.Provider, {
|
|
345
350
|
...passProps,
|
|
346
|
-
value:
|
|
351
|
+
value: value,
|
|
347
352
|
children: children
|
|
348
353
|
})
|
|
349
354
|
});
|
|
@@ -103,8 +103,9 @@ const ProductProvider = ({ children , product , initialVariantId , quantity =1
|
|
|
103
103
|
let featuredImageGlobal = undefined;
|
|
104
104
|
if (product) {
|
|
105
105
|
const variants = flattenConnection.flattenConnection(product.variants);
|
|
106
|
-
const firstVariant =
|
|
107
|
-
const
|
|
106
|
+
const firstVariant = variants[0];
|
|
107
|
+
const firstVariantInStock = variants.find((item)=>useProduct.checkInStock(item));
|
|
108
|
+
const initialVariant = variants.find((v)=>v?.id === initialVariantId) ?? firstVariantInStock ?? firstVariant;
|
|
108
109
|
selectedOptions = initialVariant?.selectedOptions.reduce((acc, option)=>{
|
|
109
110
|
if (option.name) {
|
|
110
111
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useContext, createContext, Suspense, Fragment } from 'react';
|
|
2
|
+
import { useMemo, useContext, createContext, Suspense, Fragment } from 'react';
|
|
3
3
|
import { useStore, createStore } from 'zustand';
|
|
4
4
|
import { cloneDeep } from '../helpers/clone-deep.js';
|
|
5
5
|
import { normalizeBuilderData } from '../helpers/normalize-builder-data.js';
|
|
@@ -338,10 +338,15 @@ const createBuilderPreviewProvider = (args)=>createStore((set, get)=>({
|
|
|
338
338
|
}));
|
|
339
339
|
const BuilderPreviewProvider = ({ children , state , lazy , ...passProps })=>{
|
|
340
340
|
const Component = lazy ? Suspense : Fragment;
|
|
341
|
+
const value = useMemo(()=>{
|
|
342
|
+
return createBuilderPreviewProvider(state);
|
|
343
|
+
}, [
|
|
344
|
+
state
|
|
345
|
+
]);
|
|
341
346
|
return /*#__PURE__*/ jsx(Component, {
|
|
342
347
|
children: /*#__PURE__*/ jsx(BuilderPreviewContext.Provider, {
|
|
343
348
|
...passProps,
|
|
344
|
-
value:
|
|
349
|
+
value: value,
|
|
345
350
|
children: children
|
|
346
351
|
})
|
|
347
352
|
});
|
|
@@ -101,8 +101,9 @@ const ProductProvider = ({ children , product , initialVariantId , quantity =1
|
|
|
101
101
|
let featuredImageGlobal = undefined;
|
|
102
102
|
if (product) {
|
|
103
103
|
const variants = flattenConnection(product.variants);
|
|
104
|
-
const firstVariant =
|
|
105
|
-
const
|
|
104
|
+
const firstVariant = variants[0];
|
|
105
|
+
const firstVariantInStock = variants.find((item)=>checkInStock(item));
|
|
106
|
+
const initialVariant = variants.find((v)=>v?.id === initialVariantId) ?? firstVariantInStock ?? firstVariant;
|
|
106
107
|
selectedOptions = initialVariant?.selectedOptions.reduce((acc, option)=>{
|
|
107
108
|
if (option.name) {
|
|
108
109
|
return {
|