Page MenuHomePhabricator

[native] move threadInfo caching logic
ClosedPublic

Authored by michal on Sep 15 2022, 2:32 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 15, 6:40 PM
Unknown Object (File)
Tue, May 7, 1:10 AM
Unknown Object (File)
Fri, Apr 19, 5:40 PM
Unknown Object (File)
Thu, Apr 18, 4:48 PM
Unknown Object (File)
Thu, Apr 18, 4:48 PM
Unknown Object (File)
Thu, Apr 18, 4:48 PM
Unknown Object (File)
Thu, Apr 18, 4:48 PM
Unknown Object (File)
Thu, Apr 18, 4:38 PM
Subscribers

Details

Summary

We no longer use navigation params directly in the inner component and moving caching logic of threadInfo to the outer component makes that clearer.

Depends on D5142

Test Plan

Check that if you change some value in settings (e.g. color) and log out, the settings screen that "blinks" for a moment has an updated value.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

ashoat requested changes to this revision.Sep 16 2022, 7:09 AM
ashoat added inline comments.
native/chat/settings/thread-settings.react.js
294–301 ↗(On Diff #16691)

From D5142:

These changes make sense, but I would also consider moving them to a React.useEffect in ConnectedThreadSettings... feels a little cleaner that way

1082 ↗(On Diff #16691)

Nit

This revision now requires changes to proceed.Sep 16 2022, 7:10 AM
ashoat requested changes to this revision.Sep 19 2022, 6:56 AM
ashoat added inline comments.
native/chat/settings/thread-settings.react.js
261–281

This code can also be moved to a React.useEffect now, but I think that could be a separate diff

1084

Nit: we usually just specify React.useEffect on the team, rather than separately importing it. Would you mind making this change?

1093

This is the same logic as before, but we can actually improve it now.

The intention here is: "If the thread's not in the chat list, make sure it's watched. If the thread joins the chat list, or if the threadID changes, or if the component is unmounted, make sure we stop watching the thread."

We can handle that with fewer wasted operations this way:

React.useEffect(() => {
  if (threadInChatList(threadInfo)) {
    return undefined;
  }
  threadWatcher.watchID(threadInfo.id);
  return () => {
    threadWatcher.removeID(threadInfo.id);
  };
}, [threadInfo]);

This code is better because:

  1. Each removeID call is paired 1-1 with a watchID call. Previously, a permissions change could cause a weird effect where we call watchID without calling removeID. (This was the case before your diff as well.)
  2. We exit early
This revision now requires changes to proceed.Sep 19 2022, 6:56 AM

Should I create a separate task for moving tabNavigation listener to useEffect or just continue on this?

Should I create a separate task for moving tabNavigation listener to useEffect or just continue on this?

Up to you! I would probably create a separate task personally, but it's okay either way.

This revision is now accepted and ready to land.Sep 19 2022, 10:35 AM