@nok-integration/storefront-react 0.19.25 → 0.19.26

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/index.mjs CHANGED
@@ -10666,37 +10666,50 @@ function CategoryView({ code, initialData, onNotFound }) {
10666
10666
  function ProductView({ sku, initialData, showRecommendations = true, onNotFound }) {
10667
10667
  const t = useT();
10668
10668
  const { api, market, emit } = useShop();
10669
- const [product, setProduct] = useState(initialData?.product ?? null);
10670
- const [inventory2, setInventory] = useState(initialData?.inventory ?? null);
10671
- const [recommendations, setRecommendations] = useState([]);
10672
- const [error2, setError] = useState();
10673
- const [loading, setLoading] = useState(!initialData);
10669
+ const [loaded, setLoaded] = useState(initialData ? {
10670
+ sku,
10671
+ product: initialData.product,
10672
+ inventory: initialData.inventory ?? null,
10673
+ recommendations: []
10674
+ } : null);
10675
+ const [failure, setFailure] = useState(null);
10676
+ const current2 = loaded?.sku === sku ? loaded : null;
10677
+ const error2 = failure?.sku === sku ? failure.code : void 0;
10674
10678
  useEffect(() => {
10675
10679
  let live = true;
10676
- setError(void 0);
10677
10680
  (async () => {
10678
10681
  try {
10679
10682
  const p = await api.catalog.getProduct(sku, market);
10680
10683
  if (!live) return;
10681
- setProduct(p);
10684
+ setLoaded({
10685
+ sku,
10686
+ product: p,
10687
+ inventory: null,
10688
+ recommendations: []
10689
+ });
10682
10690
  const hasVariants = (p.variants?.length ?? 0) > 0;
10683
10691
  const [inv, recs] = await Promise.allSettled([hasVariants ? Promise.resolve(null) : api.inventory.get(sku), showRecommendations ? api.catalog.getRecommendations(sku, market) : Promise.resolve({
10684
10692
  data: []
10685
10693
  })]);
10686
10694
  if (!live) return;
10687
- setInventory(inv.status === "fulfilled" ? inv.value : null);
10688
- setRecommendations(recs.status === "fulfilled" ? recs.value.data : []);
10695
+ setLoaded({
10696
+ sku,
10697
+ product: p,
10698
+ inventory: inv.status === "fulfilled" ? inv.value : null,
10699
+ recommendations: recs.status === "fulfilled" ? recs.value.data : []
10700
+ });
10689
10701
  } catch (err) {
10690
10702
  if (!live) return;
10691
10703
  const c = codeOf(err);
10692
- setError(c);
10704
+ setFailure({
10705
+ sku,
10706
+ code: c
10707
+ });
10693
10708
  emit({
10694
10709
  type: "error",
10695
10710
  code: c,
10696
10711
  scope: "product"
10697
10712
  });
10698
- } finally {
10699
- if (live) setLoading(false);
10700
10713
  }
10701
10714
  })();
10702
10715
  return () => {
@@ -10717,26 +10730,23 @@ function ProductView({ sku, initialData, showRecommendations = true, onNotFound
10717
10730
  });
10718
10731
  return unavailable;
10719
10732
  }
10720
- if (product) {
10733
+ if (current2) {
10721
10734
  return jsx(ProductDetail, {
10722
- product,
10723
- inventory: inventory2,
10724
- recommendations
10735
+ product: current2.product,
10736
+ inventory: current2.inventory,
10737
+ recommendations: current2.recommendations
10725
10738
  });
10726
10739
  }
10727
- if (loading) return jsx(ScreenSkeleton, {
10740
+ if (!error2) return jsx(ScreenSkeleton, {
10728
10741
  tone: "light"
10729
10742
  });
10730
- if (error2) {
10731
- return jsx(ShopSurface, {
10732
- tone: "light",
10733
- fill: true,
10734
- children: jsx(ErrorState, {
10735
- code: error2
10736
- })
10737
- });
10738
- }
10739
- return unavailable;
10743
+ return jsx(ShopSurface, {
10744
+ tone: "light",
10745
+ fill: true,
10746
+ children: jsx(ErrorState, {
10747
+ code: error2
10748
+ })
10749
+ });
10740
10750
  }
10741
10751
  const showcase = "_showcase_1qnt2_44";
10742
10752
  const panel = "_panel_1qnt2_48";
@@ -10666,37 +10666,50 @@ function CategoryView({ code, initialData, onNotFound }) {
10666
10666
  function ProductView({ sku, initialData, showRecommendations = true, onNotFound }) {
10667
10667
  const t = useT();
10668
10668
  const { api, market, emit } = useShop();
10669
- const [product, setProduct] = useState(initialData?.product ?? null);
10670
- const [inventory2, setInventory] = useState(initialData?.inventory ?? null);
10671
- const [recommendations, setRecommendations] = useState([]);
10672
- const [error2, setError] = useState();
10673
- const [loading, setLoading] = useState(!initialData);
10669
+ const [loaded, setLoaded] = useState(initialData ? {
10670
+ sku,
10671
+ product: initialData.product,
10672
+ inventory: initialData.inventory ?? null,
10673
+ recommendations: []
10674
+ } : null);
10675
+ const [failure, setFailure] = useState(null);
10676
+ const current2 = loaded?.sku === sku ? loaded : null;
10677
+ const error2 = failure?.sku === sku ? failure.code : void 0;
10674
10678
  useEffect(() => {
10675
10679
  let live = true;
10676
- setError(void 0);
10677
10680
  (async () => {
10678
10681
  try {
10679
10682
  const p = await api.catalog.getProduct(sku, market);
10680
10683
  if (!live) return;
10681
- setProduct(p);
10684
+ setLoaded({
10685
+ sku,
10686
+ product: p,
10687
+ inventory: null,
10688
+ recommendations: []
10689
+ });
10682
10690
  const hasVariants = (p.variants?.length ?? 0) > 0;
10683
10691
  const [inv, recs] = await Promise.allSettled([hasVariants ? Promise.resolve(null) : api.inventory.get(sku), showRecommendations ? api.catalog.getRecommendations(sku, market) : Promise.resolve({
10684
10692
  data: []
10685
10693
  })]);
10686
10694
  if (!live) return;
10687
- setInventory(inv.status === "fulfilled" ? inv.value : null);
10688
- setRecommendations(recs.status === "fulfilled" ? recs.value.data : []);
10695
+ setLoaded({
10696
+ sku,
10697
+ product: p,
10698
+ inventory: inv.status === "fulfilled" ? inv.value : null,
10699
+ recommendations: recs.status === "fulfilled" ? recs.value.data : []
10700
+ });
10689
10701
  } catch (err) {
10690
10702
  if (!live) return;
10691
10703
  const c = codeOf(err);
10692
- setError(c);
10704
+ setFailure({
10705
+ sku,
10706
+ code: c
10707
+ });
10693
10708
  emit({
10694
10709
  type: "error",
10695
10710
  code: c,
10696
10711
  scope: "product"
10697
10712
  });
10698
- } finally {
10699
- if (live) setLoading(false);
10700
10713
  }
10701
10714
  })();
10702
10715
  return () => {
@@ -10717,26 +10730,23 @@ function ProductView({ sku, initialData, showRecommendations = true, onNotFound
10717
10730
  });
10718
10731
  return unavailable;
10719
10732
  }
10720
- if (product) {
10733
+ if (current2) {
10721
10734
  return jsx(ProductDetail, {
10722
- product,
10723
- inventory: inventory2,
10724
- recommendations
10735
+ product: current2.product,
10736
+ inventory: current2.inventory,
10737
+ recommendations: current2.recommendations
10725
10738
  });
10726
10739
  }
10727
- if (loading) return jsx(ScreenSkeleton, {
10740
+ if (!error2) return jsx(ScreenSkeleton, {
10728
10741
  tone: "light"
10729
10742
  });
10730
- if (error2) {
10731
- return jsx(ShopSurface, {
10732
- tone: "light",
10733
- fill: true,
10734
- children: jsx(ErrorState, {
10735
- code: error2
10736
- })
10737
- });
10738
- }
10739
- return unavailable;
10743
+ return jsx(ShopSurface, {
10744
+ tone: "light",
10745
+ fill: true,
10746
+ children: jsx(ErrorState, {
10747
+ code: error2
10748
+ })
10749
+ });
10740
10750
  }
10741
10751
  const showcase = "_showcase_1qnt2_44";
10742
10752
  const panel = "_panel_1qnt2_48";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nok-integration/storefront-react",
3
- "version": "0.19.25",
3
+ "version": "0.19.26",
4
4
  "description": "Mountable React storefront components: catalogue, product detail and cart, mounted directly into a host DOM tree. No iframe.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {