emoji-picker-react 4.20.0 → 4.20.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.
@@ -520,11 +520,10 @@ function useDebouncedState(initialValue, delay) {
520
520
  var timer = useRef(null);
521
521
  function debouncedSetState(value) {
522
522
  return new Promise(function (resolve) {
523
- var _window;
524
523
  if (timer.current) {
525
524
  clearTimeout(timer.current);
526
525
  }
527
- timer.current = (_window = window) == null ? void 0 : _window.setTimeout(function () {
526
+ timer.current = setTimeout(function () {
528
527
  setState(value);
529
528
  resolve(value);
530
529
  }, delay);
@@ -26744,14 +26743,24 @@ var defaultEmojiData = {
26744
26743
  emojis: emojis
26745
26744
  };
26746
26745
 
26746
+ function useIsMounted() {
26747
+ var _React$useState = useState(false),
26748
+ isMounted = _React$useState[0],
26749
+ setIsMounted = _React$useState[1];
26750
+ useEffect(function () {
26751
+ setIsMounted(true);
26752
+ }, []);
26753
+ return isMounted;
26754
+ }
26755
+
26747
26756
  var SUGGESTED_LS_KEY = 'epr_suggested';
26748
26757
  function getSuggested(mode) {
26749
26758
  try {
26750
- var _window, _window$localStorage$, _window2;
26751
- if (!((_window = window) != null && _window.localStorage)) {
26759
+ var _window$localStorage$;
26760
+ if (typeof window === 'undefined' || !window.localStorage) {
26752
26761
  return [];
26753
26762
  }
26754
- var recent = JSON.parse((_window$localStorage$ = (_window2 = window) == null ? void 0 : _window2.localStorage.getItem(SUGGESTED_LS_KEY)) != null ? _window$localStorage$ : '[]');
26763
+ var recent = JSON.parse((_window$localStorage$ = window.localStorage.getItem(SUGGESTED_LS_KEY)) != null ? _window$localStorage$ : '[]');
26755
26764
  if (mode === SuggestionMode.FREQUENT) {
26756
26765
  return recent.sort(function (a, b) {
26757
26766
  return b.count - a.count;
@@ -26786,8 +26795,10 @@ function setSuggested(emoji, skinTone) {
26786
26795
  existing.count++;
26787
26796
  nextList.length = Math.min(nextList.length, 14);
26788
26797
  try {
26789
- var _window3;
26790
- (_window3 = window) == null ? void 0 : _window3.localStorage.setItem(SUGGESTED_LS_KEY, JSON.stringify(nextList));
26798
+ if (typeof window === 'undefined') {
26799
+ return;
26800
+ }
26801
+ window.localStorage.setItem(SUGGESTED_LS_KEY, JSON.stringify(nextList));
26791
26802
  // Prevents the change from being seen immediately.
26792
26803
  } catch (_unused2) {
26793
26804
  // ignore
@@ -26826,15 +26837,21 @@ function useGetEmojisByCategory() {
26826
26837
  var suggestedEmojisModeConfig = useSuggestedEmojisModeConfig();
26827
26838
  var _useUpdateSuggested = useUpdateSuggested(),
26828
26839
  suggestedUpdated = _useUpdateSuggested[0];
26840
+ // Suggestions come from localStorage, which doesn't exist during SSR.
26841
+ // Read them only after mount so the first client render matches the server.
26842
+ var isMounted = useIsMounted();
26829
26843
  var suggested = React__default.useMemo(function () {
26830
26844
  var _getSuggested;
26845
+ if (!isMounted) {
26846
+ return [];
26847
+ }
26831
26848
  var suggested = (_getSuggested = getSuggested(suggestedEmojisModeConfig)) != null ? _getSuggested : [];
26832
26849
  return suggested.map(function (s) {
26833
26850
  return emojiByUnified(s.unified);
26834
26851
  }).filter(Boolean);
26835
26852
  },
26836
26853
  // eslint-disable-next-line react-hooks/exhaustive-deps
26837
- [suggestedUpdated, suggestedEmojisModeConfig]);
26854
+ [isMounted, suggestedUpdated, suggestedEmojisModeConfig]);
26838
26855
  return function getEmojisByCategory(category) {
26839
26856
  var _emojis$emojis$catego;
26840
26857
  if (category === Categories.SUGGESTED) {
@@ -26957,8 +26974,14 @@ function useGetEmojisByCategory$1() {
26957
26974
  var suggestedEmojisModeConfig = useSuggestedEmojisModeConfig();
26958
26975
  var _useUpdateSuggested = useUpdateSuggested(),
26959
26976
  suggestedUpdated = _useUpdateSuggested[0];
26977
+ // Suggestions come from localStorage, which doesn't exist during SSR.
26978
+ // Read them only after mount so the first client render matches the server.
26979
+ var isMounted = useIsMounted();
26960
26980
  var suggested = React__default.useMemo(function () {
26961
26981
  var _getSuggested;
26982
+ if (!isMounted) {
26983
+ return [];
26984
+ }
26962
26985
  var suggested = (_getSuggested = getSuggested(suggestedEmojisModeConfig)) != null ? _getSuggested : [];
26963
26986
  return suggested.map(function (s) {
26964
26987
  var _extends2;
@@ -26967,7 +26990,7 @@ function useGetEmojisByCategory$1() {
26967
26990
  return _extends({}, emoji, (_extends2 = {}, _extends2[EmojiProperties.unified] = s.unified, _extends2));
26968
26991
  }).filter(Boolean);
26969
26992
  // eslint-disable-next-line react-hooks/exhaustive-deps
26970
- }, [suggestedUpdated, suggestedEmojisModeConfig, emojiByUnified]);
26993
+ }, [isMounted, suggestedUpdated, suggestedEmojisModeConfig, emojiByUnified]);
26971
26994
  return function getEmojisByCategory(category) {
26972
26995
  var _emojiData$emojis$cat, _emojiData$emojis;
26973
26996
  if (category === Categories.SUGGESTED) {
@@ -28799,7 +28822,6 @@ function useMouseDownHandlers(ContainerRef, mouseEventSource) {
28799
28822
  onEmojiClick(emojiClickOutput(emoji, skinToneToUse, activeEmojiStyle, getEmojiUrl), event);
28800
28823
  }, [activeSkinTone, closeAllOpenToggles, disallowClickRef, emojiByUnified, onEmojiClick, updateSuggested, getEmojiUrl, activeEmojiStyle]);
28801
28824
  var onMouseDown = useCallback(function onMouseDown(event) {
28802
- var _window;
28803
28825
  if (mouseDownTimerRef.current) {
28804
28826
  clearTimeout(mouseDownTimerRef.current);
28805
28827
  }
@@ -28808,7 +28830,7 @@ function useMouseDownHandlers(ContainerRef, mouseEventSource) {
28808
28830
  if (!emoji || !emojiHasVariations$1(emoji)) {
28809
28831
  return;
28810
28832
  }
28811
- mouseDownTimerRef.current = (_window = window) == null ? void 0 : _window.setTimeout(function () {
28833
+ mouseDownTimerRef.current = setTimeout(function () {
28812
28834
  disallowClickRef.current = true;
28813
28835
  mouseDownTimerRef.current = undefined;
28814
28836
  closeAllOpenToggles();
@@ -29546,6 +29568,10 @@ var styles$7 = /*#__PURE__*/stylesheet.create({
29546
29568
  }
29547
29569
  });
29548
29570
 
29571
+ // `useLayoutEffect` warns during SSR since it never runs on the server.
29572
+ // Fall back to `useEffect` there: measurement only matters on the client.
29573
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
29574
+
29549
29575
  function MeasureEmoji() {
29550
29576
  var categories = useCategoriesConfig();
29551
29577
  var getEmojisByCategory = useGetEmojisByCategory();
@@ -29558,7 +29584,7 @@ function MeasureEmoji() {
29558
29584
  emojiSize = _useEmojiSizeState[0],
29559
29585
  setEmojiSize = _useEmojiSizeState[1];
29560
29586
  var ref = useRef(null);
29561
- useLayoutEffect(function () {
29587
+ useIsomorphicLayoutEffect(function () {
29562
29588
  if (ref.current) {
29563
29589
  setEmojiSize(ref.current.clientHeight);
29564
29590
  }