Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: improve channel preview display hooks and long title issue #3002

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

khushal87
Copy link
Member

The goal of the PR is to improve the channel preview display hooks to use useMemo instead of a combination of useState and useEffect for the calculation that would take an additional render.

Also, the title logic for the channel preview is improved for channels that have long names. This was a UI issue that was easily noticeable and looked bad.

I am open to discussion if anything doesn't seem correct here.

@Stream-SDK-Bot
Copy link
Contributor

SDK Size

title develop branch diff status
js_bundle_size 466 KB 466 KB 0 B 🟢

}, [channel, channelMemberOnline, client]);
const displayPresence = useMemo(() => {
return getChannelPreviewDisplayPresence(channel, client);
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this, why is eslint complaining ? If we do, let's try to fix the hook instead of disabling the rule

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for the additional channelMemberOnline dep

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should not be the case, that one was there before too and it was also the dependency of a hook.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, its weird that it didn't complain before

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless, the issue with the dependencies should be fixed; we should not introduce any more of the eslint-disable comments unless we have a very very good reason to do so

const [latestMessagePreview, setLatestMessagePreview] = useState<
LatestMessagePreview<StreamChatGenerics>
>({
created_at: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be for the better (since the default state seems very broken anyway), but please check and make sure that we don't have code in the downstream components that depends on this (since it's being removed).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't see any noticeable bug post this change

);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [channelName, currentUserId, characterLimit, numOfMembers]);
[channelName, characterLimit, currentUserId, members],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably aren't sure that members will change its reference each time a member is added (for example, it may very well be the fact that it gets mutated rather than copied on write, as we can see in the other hooks).

I would keep both members and numMembers here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for the time being at least, until we convert channel to be fully reactive)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants