trendmicro-frontend / tonic-ui

Tonic UI is a UI component library for React, built with Emotion and Styled System. It is designed to be easy to use and easy to customize.
https://trendmicro-frontend.github.io/tonic-ui
MIT License
125 stars 28 forks source link

Composition events (Chinese, Japanese IME) problem in controlled `SearchInput` component #849

Closed cheton closed 3 months ago

cheton commented 3 months ago

Description

Chinese characters entered via the Chinese Pinyin input method trigger excessive renders, as shown below in the "Keyword Search" example:

May-08-2024 09-54-26

Note: This issue only occurred in v1. v0 does not have this problem.

Several related issues have been identified:

Resolution

To resolve this issue, it's recommended to set the value immediately for controlled input or textarea, regardless of whether it's controlled or not.

   const onChange = useCallback((e) => {
     const nextValue = ensureString(e.target.value ?? '');
-    const isControlled = (valueProp !== undefined);
-
-    if (!isControlled) {
-      setValue(nextValue);
-    }
+    setValue(nextValue);