@sonic-equipment/ui 1.1.4 → 1.1.5

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.
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx } from 'react/jsx-runtime';
3
- import { createContext, useState, useMemo, useRef, useEffect } from 'react';
3
+ import { createContext, useState, useRef, useEffect, useMemo } from 'react';
4
4
  import { config } from '../config.js';
5
5
  import { categoriesPlugin } from '../global-search/plugins/categories-plugin.js';
6
6
  import { popularCategoriesPlugin } from '../global-search/plugins/popular-categories-plugin.js';
@@ -30,6 +30,23 @@ function AlgoliaSearchProvider({ children, searchClient: _searchClient, }) {
30
30
  query: '',
31
31
  status: 'idle',
32
32
  });
33
+ // `createAutocomplete` is instantiated in a `useMemo` below, and its
34
+ // plugins (notably the Algolia insights plugin) can synchronously kick
35
+ // off `onStateChange` before the component has committed/mounted — e.g.
36
+ // when `window.aa`'s insights queue already resolved from a prior render
37
+ // (React Strict Mode's double-invoke, or a Fast Refresh remount). Calling
38
+ // `setState` at that point trips React's "state update on a component
39
+ // that hasn't mounted yet" warning. Buffer any pre-mount update and flush
40
+ // it once mounted instead of calling `setState` directly from render.
41
+ const isMountedRef = useRef(false);
42
+ const pendingStateRef = useRef(null);
43
+ useEffect(() => {
44
+ isMountedRef.current = true;
45
+ if (pendingStateRef.current) {
46
+ setState(pendingStateRef.current);
47
+ pendingStateRef.current = null;
48
+ }
49
+ }, []);
33
50
  const searchClient = useMemo(() => _searchClient ||
34
51
  createSonicSearchClient({
35
52
  apiKey: config.ALGOLIA_API_KEY,
@@ -86,7 +103,12 @@ function AlgoliaSearchProvider({ children, searchClient: _searchClient, }) {
86
103
  getSources,
87
104
  insights: true,
88
105
  onStateChange({ state }) {
89
- setState(state);
106
+ if (isMountedRef.current) {
107
+ setState(state);
108
+ }
109
+ else {
110
+ pendingStateRef.current = state;
111
+ }
90
112
  },
91
113
  openOnFocus: true,
92
114
  plugins: [
@@ -63,7 +63,7 @@ className, currentShipToId, }) {
63
63
  Math.random().toString(36).slice(2, 15) + currentShipToId,
64
64
  ];
65
65
  }, [data?.shipTos, error, hasMoreResults, t, currentShipToId]);
66
- return (jsxs("div", { className: clsx(styles['address-book-selector-container'], className), children: [jsx(SearchField, { autoFocus: true, isDebounced: true, "aria-controls": "filtered-address-results-list", isDisabled: isFetching, isLoading: isFetching, label: t('Search addresses'), onChange: setSearch, onKeyUp: ({ key }) => {
66
+ return (jsxs("div", { className: clsx(styles['address-book-selector-container'], className), children: [jsx(SearchField, { autoFocus: true, isDebounced: true, "aria-controls": "filtered-address-results-list", "data-test-selector": "search-shipping-adress-field", isDisabled: isFetching, isLoading: isFetching, label: t('Search addresses'), onChange: setSearch, onKeyUp: ({ key }) => {
67
67
  if (key === 'ArrowDown') {
68
68
  listBoxRef.current?.focus();
69
69
  }
@@ -19,7 +19,7 @@ function ShipToModeSelector(props) {
19
19
  // useDefaultShipTo: props.shipToInfoDisplay,
20
20
  useNewAddress: props.newAddressForm,
21
21
  }[shippingOption];
22
- return (jsxs(Fragment, { children: [jsx(SelectField, { "data-test-selector": "order-history-filter", label: t('Shipping address'), name: "shippingType", onChange: setShippingOption, options: options, selectedOption: shippingOption, showLabel: false }), additionalComponentForShipping] }));
22
+ return (jsxs(Fragment, { children: [jsx(SelectField, { "data-test-selector": "select-shipping-adress", label: t('Shipping address'), name: "shippingType", onChange: setShippingOption, options: options, selectedOption: shippingOption, showLabel: false }), additionalComponentForShipping] }));
23
23
  }
24
24
 
25
25
  export { ShipToModeSelector as default };
@@ -83,7 +83,7 @@ function ConnectedCreateShipToAddressForm({ billToId, makeDefault, returnUrl, })
83
83
  });
84
84
  }
85
85
  return navigate(`${paths.ACCOUNT_EDIT_BILL_TO_ADDRESS}/${billToId}${paths.ACCOUNT_EDIT_SHIP_TO_ADDRESS}/${createdShipToAddress.id}?returnUrl=${encodeURIComponent(returnUrl || '')}`);
86
- }, children: [jsx(AddressForm, { address: undefined, countries: countries, currentCountry: currentCountry, isLoading: isPatching }), jsx(Checkbox, { defaultSelected: makeDefault, isDisabled: isPatching, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) }), Boolean(errorShipToAddress) && (jsx("div", { className: styles.info, children: jsx(Message, { type: "danger", children: jsx(FormattedMessage, { id: "An unexpected error occured" }) }) })), isSuccess && !isPatching && (jsx("div", { className: styles.info, children: jsx(Message, { type: "info", children: jsx(FormattedMessage, { id: "Saved" }) }) })), jsxs("div", { className: styles.actions, children: [returnUrl && (jsx(Button, { color: "secondary", isDisabled: isPatching, onClick: () => navigate(returnUrl), variant: "outline", children: jsx(FormattedMessage, { id: "Back" }) })), jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) })] })] }));
86
+ }, children: [jsx(AddressForm, { address: undefined, countries: countries, currentCountry: currentCountry, isLoading: isPatching }), jsx(Checkbox, { "data-test-selector": "makeDefaultShippingAddress", defaultSelected: makeDefault, isDisabled: isPatching, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) }), Boolean(errorShipToAddress) && (jsx("div", { className: styles.info, children: jsx(Message, { type: "danger", children: jsx(FormattedMessage, { id: "An unexpected error occured" }) }) })), isSuccess && !isPatching && (jsx("div", { className: styles.info, children: jsx(Message, { type: "info", children: jsx(FormattedMessage, { id: "Saved" }) }) })), jsxs("div", { className: styles.actions, children: [returnUrl && (jsx(Button, { color: "secondary", isDisabled: isPatching, onClick: () => navigate(returnUrl), variant: "outline", children: jsx(FormattedMessage, { id: "Back" }) })), jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) })] })] }));
87
87
  }
88
88
 
89
89
  export { ConnectedCreateShipToAddressForm };
@@ -123,7 +123,7 @@ function ConnectedEditShipToAddressForm({ billToId, returnUrl, shipToId, }) {
123
123
  },
124
124
  });
125
125
  }
126
- }, children: [jsx(AddressForm, { address: shipToAddress, countries: countries, currentCountry: currentCountry, isLoading: isPatching, isReadonly: isReadonly || isPatching }), shipToAddress.id !== 'current' && (jsxs(Fragment, { children: [jsx(Checkbox, { defaultSelected: shipToAddress.isDefault, isDisabled: isReadonly || isPatching || hasCartItems, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) }), hasCartItems && (jsx("div", { className: styles.info, children: jsx(Message, { type: "info", children: jsx(FormattedMessage, { id: "You cannot change the default ship to address while there are items in your cart." }) }) }))] })), isSuccess && !isPatching && (jsx("div", { className: styles.info, children: jsx(Message, { type: "success", children: jsx(FormattedMessage, { id: "Saved" }) }) })), jsxs("div", { className: styles.actions, children: [returnUrl && (jsx(Button, { color: "secondary", isDisabled: isPatching, onClick: () => navigate(returnUrl), variant: "outline", children: jsx(FormattedMessage, { id: "Back" }) })), !isReadonly && (jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) }))] })] }));
126
+ }, children: [jsx(AddressForm, { address: shipToAddress, countries: countries, currentCountry: currentCountry, isLoading: isPatching, isReadonly: isReadonly || isPatching }), shipToAddress.id !== 'current' && (jsxs(Fragment, { children: [jsx(Checkbox, { "data-test-selector": "makeDefaultShippingAddress", defaultSelected: shipToAddress.isDefault, isDisabled: isReadonly || isPatching || hasCartItems, name: "setAsDefault", value: "TRUE", children: jsx(FormattedMessage, { id: "Make this the default ship to address" }) }), hasCartItems && (jsx("div", { className: styles.info, children: jsx(Message, { type: "info", children: jsx(FormattedMessage, { id: "You cannot change the default ship to address while there are items in your cart." }) }) }))] })), isSuccess && !isPatching && (jsx("div", { className: styles.info, children: jsx(Message, { type: "success", children: jsx(FormattedMessage, { id: "Saved" }) }) })), jsxs("div", { className: styles.actions, children: [returnUrl && (jsx(Button, { color: "secondary", isDisabled: isPatching, onClick: () => navigate(returnUrl), variant: "outline", children: jsx(FormattedMessage, { id: "Back" }) })), !isReadonly && (jsx(Button, { isLoading: isPatching ? jsx(FormattedMessage, { id: "Saving" }) : undefined, type: "submit", children: jsx(FormattedMessage, { id: "Save" }) }))] })] }));
127
127
  }
128
128
 
129
129
  export { ConnectedEditShipToAddressForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {