diff --git a/src/common/LazyEmojiPicker.tsx b/src/common/LazyEmojiPicker.tsx new file mode 100644 index 0000000..6814b07 --- /dev/null +++ b/src/common/LazyEmojiPicker.tsx @@ -0,0 +1,32 @@ +import { ComponentType, FC, lazy, Suspense } from 'react'; + +type EmojiPickerProps = Record; + +/** + * emoji-mart's data bundle (`@emoji-mart/data`) is ~430 KB (~82 KB gzip) and was + * pulled into the initial app bundle by three always-mounted views that import it + * statically. The picker itself opens rarely, so we load both the data and the + * `` component on demand via a dynamic import — deferring that payload out + * of first paint. Drop-in for `` (the `data` prop is + * injected here; forward every other prop unchanged). + */ +const PickerWithData = lazy(async () => +{ + const [ dataModule, pickerModule ] = await Promise.all([ + import('@emoji-mart/data'), + import('@emoji-mart/react') + ]); + + const data = (dataModule as { default: unknown }).default; + const Picker = (pickerModule as { default: ComponentType }).default; + + const Wrapped: ComponentType = props => ; + + return { default: Wrapped }; +}); + +export const LazyEmojiPicker: FC = props => ( + … }> + + +); diff --git a/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx b/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx index 24d04f7..7dad661 100644 --- a/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx +++ b/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx @@ -2,8 +2,7 @@ import { PurchasePrefixComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useMemo, useRef, useState } from 'react'; import { LocalizeText, SanitizeHtml, SendMessageComposer, PRESET_PREFIX_EFFECTS, parsePrefixColors, getPrefixEffectStyle, PREFIX_EFFECT_KEYFRAMES } from '../../../../../api'; import { CatalogLayoutProps } from './CatalogLayout.types'; -import data from '@emoji-mart/data'; -import Picker from '@emoji-mart/react'; +import { LazyEmojiPicker } from '../../../../../common/LazyEmojiPicker'; const PRESET_COLORS: string[] = [ '#FF0000', '#FF6600', '#FFCC00', '#33CC00', '#00CCFF', @@ -222,8 +221,7 @@ export const CatalogLayoutCustomPrefixView: FC = props => <>
setShowIconPicker(false) } />
- { diff --git a/src/components/customize/CustomizeNickIconView.tsx b/src/components/customize/CustomizeNickIconView.tsx index 6485527..0e6cb68 100644 --- a/src/components/customize/CustomizeNickIconView.tsx +++ b/src/components/customize/CustomizeNickIconView.tsx @@ -1,6 +1,5 @@ import { AddLinkEventTracker, CustomPrefixPurchaseFailedEvent, ILinkEventTracker, PurchaseCatalogPrefixComposer, PurchaseNickIconComposer, PurchasePrefixComposer, RemoveLinkEventTracker, RequestNickIconsComposer, SetActiveNickIconComposer, SetActivePrefixComposer, SetDisplayOrderComposer, UserNickIconsEvent } from '@nitrots/nitro-renderer'; -import data from '@emoji-mart/data'; -import Picker from '@emoji-mart/react'; +import { LazyEmojiPicker } from '../../common/LazyEmojiPicker'; import { FC, useEffect, useMemo, useState } from 'react'; import { INickIconItem, IPrefixItem, PRESET_PREFIX_EFFECTS, PRESET_PREFIX_FONTS, SendMessageComposer, getPrefixEffectStyle, getPrefixFontStyle, parsePrefixColors } from '../../api'; import { GetNickIconUrl } from '../../assets/images/user_custom/nick_icons'; @@ -575,8 +574,7 @@ export const CustomizeNickIconView: FC<{}> = () => <>
setShowEmojiPicker(false) } />
- { diff --git a/src/components/room/widgets/chat-input/ChatInputEmojiSelectorView.tsx b/src/components/room/widgets/chat-input/ChatInputEmojiSelectorView.tsx index bd2dcae..6f8708b 100644 --- a/src/components/room/widgets/chat-input/ChatInputEmojiSelectorView.tsx +++ b/src/components/room/widgets/chat-input/ChatInputEmojiSelectorView.tsx @@ -1,6 +1,5 @@ -import data from '@emoji-mart/data'; -import Picker from '@emoji-mart/react'; import * as Popover from '@radix-ui/react-popover'; +import { LazyEmojiPicker } from '../../../../common/LazyEmojiPicker'; import { FC, useState } from 'react'; interface ChatInputEmojiSelectorViewProps @@ -26,7 +25,7 @@ export const ChatInputEmojiSelectorView: FC = p - +