From 694cafa5637fa16a29071f3559ce2a63ac8e6416 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 19 Jan 2023 02:25:42 -0500 Subject: [PATCH] shared fast react-select option override --- .../v2/view/_common/FastReactSelectOption.tsx | 17 ++++++++ .../explore/ScopedVoiceModelOptions.tsx | 7 +++- .../tts_model_list/search/SelectSearch.tsx | 39 +++---------------- 3 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 packages/fakeyou.com/src/v2/view/_common/FastReactSelectOption.tsx diff --git a/packages/fakeyou.com/src/v2/view/_common/FastReactSelectOption.tsx b/packages/fakeyou.com/src/v2/view/_common/FastReactSelectOption.tsx new file mode 100644 index 0000000000..994f2621ef --- /dev/null +++ b/packages/fakeyou.com/src/v2/view/_common/FastReactSelectOption.tsx @@ -0,0 +1,17 @@ +import React from "react"; +import { components } from "react-select"; + +// This is an override to library "react-select"'s default option. +// There are numerous issues with performance that this improves. +// See the detailed thread about it: https://github.com/JedWatson/react-select/issues/3128 +export class FastReactSelectOption extends React.Component { + render() { + const {innerProps, isFocused, ...otherProps} = this.props as any; + const {onMouseMove, onMouseOver, ...otherInnerProps} = innerProps; + const newProps = {innerProps: {...otherInnerProps}, ...otherProps}; + return ( + {this.props.children} + + ); + } +} diff --git a/packages/fakeyou.com/src/v2/view/tts/tts_model_list/explore/ScopedVoiceModelOptions.tsx b/packages/fakeyou.com/src/v2/view/tts/tts_model_list/explore/ScopedVoiceModelOptions.tsx index 51fac08a84..34f0c8d099 100644 --- a/packages/fakeyou.com/src/v2/view/tts/tts_model_list/explore/ScopedVoiceModelOptions.tsx +++ b/packages/fakeyou.com/src/v2/view/tts/tts_model_list/explore/ScopedVoiceModelOptions.tsx @@ -7,9 +7,10 @@ import { TtsModelListItem } from "@storyteller/components/src/api/tts/ListTtsMod import { TtsCategoryType } from "../../../../../AppWrapper"; import { Trans } from "react-i18next"; //import { Analytics } from "../../../../../common/Analytics"; -import Select from "react-select"; +import Select, { createFilter } from "react-select"; //import Option from "react-select"; import { SearchFieldClass } from "../search/SearchFieldClass"; +import { FastReactSelectOption } from "../../../_common/FastReactSelectOption"; interface Props { allTtsCategories: TtsCategoryType[]; @@ -98,6 +99,10 @@ export function ScopedVoiceModelOptions(props: Props) { options={options} classNames={SearchFieldClass} onChange={handleChange} + // NB: The following settings improve upon performance. + // See: https://github.com/JedWatson/react-select/issues/3128 + filterOption={createFilter({ignoreAccents: false})} + components={{Option: FastReactSelectOption} as any} /> diff --git a/packages/fakeyou.com/src/v2/view/tts/tts_model_list/search/SelectSearch.tsx b/packages/fakeyou.com/src/v2/view/tts/tts_model_list/search/SelectSearch.tsx index 915c927ef4..2a6365f25d 100644 --- a/packages/fakeyou.com/src/v2/view/tts/tts_model_list/search/SelectSearch.tsx +++ b/packages/fakeyou.com/src/v2/view/tts/tts_model_list/search/SelectSearch.tsx @@ -3,9 +3,10 @@ import { TtsModelListItem } from "@storyteller/components/src/api/tts/ListTtsMod import { TtsCategoryType } from "../../../../../AppWrapper"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faMicrophone } from "@fortawesome/free-solid-svg-icons"; -import Select, { ActionMeta, createFilter, components } from "react-select"; +import Select, { ActionMeta, createFilter } from "react-select"; import Option from "react-select"; import { SearchFieldClass } from "./SearchFieldClass"; +import { FastReactSelectOption } from "../../../_common/FastReactSelectOption"; // NB: This probably is not the best autocomplete library in the world // A lot of the libraries are really old and depend on jQuery (gross). @@ -64,41 +65,13 @@ export function SelectSearch(props: Props) { isSearchable={true} options={options} classNames={SearchFieldClass} - filterOption={createFilter({ignoreAccents: false})} onChange={handleChange} - components={{Option: CustomOption} as any} + // NB: The following settings improve upon performance. + // See: https://github.com/JedWatson/react-select/issues/3128 + filterOption={createFilter({ignoreAccents: false})} + components={{Option: FastReactSelectOption} as any} /> ); } - -class CustomOption extends React.Component { - //constructor(props: any) { - // super(props); - //} - - render() { - const {innerProps, isFocused, ...otherProps} = this.props as any; - const {onMouseMove, onMouseOver, ...otherInnerProps} = innerProps; - const newProps = {innerProps: {...otherInnerProps}, ...otherProps}; - return ( - {this.props.children} - - ); - } -} - -//const CustomOption2 = ({ children, ...props } : any ) => { -// const {innerProps, isFocused, ...otherProps} = props; -// const { onMouseMove, onMouseOver, ...rest } = props.innerProps; -// //const newProps = Object.assign(props, { innerProps: rest }); -// const newProps = {innerProps: {...rest}, otherProps} as any; -// return ( -// -// {children} -// -// ); -//};