Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debounce compose form #17396

Closed
wants to merge 3 commits into from
Closed

Conversation

tribela
Copy link
Contributor

@tribela tribela commented Jan 30, 2022

Compose form's textarea was in a hell of re-rendering. Especially in CJK IME
It causes missing characters on low powered machines (even on my brand-new laptop), And it happened a lot and user experience was terrible as a Korean user.

As an example, I typed 가나다 (3 letters but 6 types)

ㄱ
가
간
가나
가낟
가나다

Before

image

render 가
render 가나
render 가낟
render 가
render 가나
render 가나다
render 가나
render 가나다

I don't know why they re-render more than 6 times (Maybe multiple hooks are used for onChange, onKeyup, onKeydown).

After

image

render ㄱ
render 가
render 간
render 가나
render 가낟
render 가나다
render 가나다 
render 가나다 @
render 가나다 @a
render 가나다 @ad
render 가나다 @ad
render 가나다 @admin

I set timeout to 1ms. It is enough to remove struggling effects, And also auto suggestions (mention, emoji, hashtag) are fine

@ClearlyClaire
Copy link
Contributor

I'd much rather we find the source of these re-renders than set a debounce…

@ClearlyClaire
Copy link
Contributor

Investigating a bit more, I can't find the reason it would be re-rendered more than once per keypress, and I also can't see it render more than the compose form itself. There's definitely some optimization to be done in the compose form render itself (mainly, optimize and memoize some of canSubmit, memoize a lot of the intl.formatMessage calls), but I don't know how much of a difference it can make.

I'm not completely against debouncing the onChange callback itself, but I'm wary of adding yet another dependency, and I wonder how much we can improve the performance of the compose form rendering code overall and if it could be enough.

@ClearlyClaire
Copy link
Contributor

Everything is very fast on my computer, so I have trouble evaluating the changes, but could you check whether #17463 improves the situation for you?

@tribela
Copy link
Contributor Author

tribela commented Feb 8, 2022

Multiple render problem is caused on Firefox with compositing IME. related: facebook/react#3926
This case, debounce will help. But I agree with you to not use debounce to fix this kind of problem.

I'll check #17463 later on my beta instance

@tribela
Copy link
Contributor Author

tribela commented Feb 8, 2022

Update: I test with #17463. But sadly, Missing characters glitch happening again on my laptop with firefox.
(crome or brave has no problem. And also latin language doesn't have problem. Only Korean on firefox has this problem)

@ClearlyClaire
Copy link
Contributor

ClearlyClaire commented Feb 8, 2022

Thanks for testing! I wonder if the missing character issue is a performance issue, or React and the IME somehow fighting over the value of the textarea? Did you notice any performance improvement with #17463? Either way, we probably need something like debouncing or handling compositionstart and compositionend events, but I'm wary of the subtle bugs it might introduce.

@tribela
Copy link
Contributor Author

tribela commented Feb 8, 2022

I'm back from digging about composition[start,end,update] thing!
And finally, I found a way to fix that render thing(more than once per keystroke).

@ClearlyClaire
Copy link
Contributor

I'm back from digging about composition[start,end,update] thing! And finally, I found a way to fix that render thing(more than once per keystroke).

Do you have more on that?

@tribela
Copy link
Contributor Author

tribela commented Mar 10, 2022

Multiple renders at one keystroke was problem of IME (word commit and something else)
So, while debounce could be a partial solution, But it is not a mastodon's problem, I'll close this PR

@tribela tribela closed this Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants