Page MenuHomePhabricator

[web] Keyboard support for typeahead [13/13] - Freeze users list when typeahead is visible.
ClosedPublic

Authored by przemek on Dec 27 2022, 5:28 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 6, 6:00 PM
Unknown Object (File)
Wed, Apr 3, 4:13 PM
Unknown Object (File)
Wed, Apr 3, 4:13 PM
Unknown Object (File)
Wed, Apr 3, 4:13 PM
Unknown Object (File)
Wed, Apr 3, 4:13 PM
Unknown Object (File)
Wed, Apr 3, 4:13 PM
Unknown Object (File)
Wed, Apr 3, 4:12 PM
Unknown Object (File)
Mar 13 2024, 8:55 PM

Details

Summary

One weird edge case was deleting/adding user to chat/thread when other user had overlay displayed.
Normally overlay is rerendered with newly fetched fresh user list, but it may cause weird shifts in chosen button.
We could solve it by using some extra state to save currently chosen button and then going back to it after list of users change, but I decided to go with simpler solution: when overlay is displayed list of users is frozen until it disappears.
It may result in tries to @ users that were deleted from channel, but it doesn't seem like a huge issue.
In future we may react to it by displaying modal asking if we want to sent invite to such user (or any user that we tried to @, but who was not in out channel).

Test Plan

Added and deleted users using another account and incognito browser.
Freezing worked fine.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Spotted uncaught bug while testing later on - it caused to freeze users list in wrong situations. Moved frozen users to state in context. It works now.

Fixed problems. Took wrong aproach in the beginning.

web/chat/chat-input-bar.react.js
598–611 ↗(On Diff #20514)

We save users currently in thread.

618 ↗(On Diff #20514)

We use frozen users instead of threadMembers

web/chat/typeahead-tooltip.react.js
49–56 ↗(On Diff #20514)

We clear frozen members only when tooltip is unmounted.

tomek requested changes to this revision.Jan 4 2023, 6:49 AM
tomek added inline comments.
web/input/input-state.js
39 ↗(On Diff #20514)

I don't think it is a good idea that input state knows about internal implementation of a tooltip. We shouldn't keep frozenThreadMembers here.

When we show a typeahead, it should save the list (probably in state) and update it only when it becomes invisible.

This revision now requires changes to proceed.Jan 4 2023, 6:49 AM
web/chat/chat-input-bar.react.js
598–610 ↗(On Diff #20514)

Is this code correct? What happens when a typeahead is hidden and users list is updated a couple of times? It seems like we probably need an additional flag instead of using frozenThreadMembers for two purposes: storing members and as a flag.

web/chat/typeahead-tooltip.react.js
51–53 ↗(On Diff #20514)

We should avoid a magic value (empty array) that has a special meaning. Instead we should have a function that resets frozen members.

przemek added inline comments.
web/input/input-state.js
39 ↗(On Diff #20514)

I feel like there's no better place for it. We can't keep it inside tooltip component as it's rendered based on SuggestedUsers (that are chosen from ThreadMembers - now frozen). ConnectedChatInputbar selects threadMembers so its state feels like natural place for keeping frozen copy.

przemek marked 2 inline comments as done.

Added flag keepUpdatingThreadMembers which is set false on mounting tooltip. It causes users to threadMemebrs to get frozen.

tomek requested changes to this revision.Jan 9 2023, 3:11 AM

We're really close!

web/chat/chat-input-bar.react.js
591–602 ↗(On Diff #20627)

This is correct but can be made more efficient. Currently, we always have to rely on an effect to update the members, but the effect isn't necessary at all.

To avoid the effect, we can do two things:

  1. Every time a function that updates threadMembers is called, we can check if keepUpdatingThreadMembers and update frozenThreadMembers if appropriate
  2. Every time keepUpdatingThreadMembers is set to true, update frozenThreadMembers

These two changes can be made in setTypeaheadState which will make it more performant and easier to use.

592 ↗(On Diff #20627)

Maybe rename to areThreadMembersFrozen?

This revision now requires changes to proceed.Jan 9 2023, 3:11 AM

We've talked about that issue with Tomek. We've tried to find better solution, but it seems hard and we don't get huge benefits here.
Tomek has brought up issue, that calling useEffect that changes state will cause rerender of component. It's single rerender and every value above is memoised, so it shouldn't be huge overhead.
We've decided to go with current solution then.

Please don't forget to update the name (if you agree) before landing

This revision is now accepted and ready to land.Jan 11 2023, 8:47 AM