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

[NV-3037] Fixed closing off the wrong socket in useUnreadCount.ts #4590

Merged
merged 3 commits into from
Oct 30, 2023

Conversation

Khongchai
Copy link
Contributor

What change does this PR introduce?

This fixes an issue where the useUnreadCount hook closes the wrong websocket channel.

Why was this change needed?

#4582

Other information (Screenshots)

@djabarovgeorge
Copy link
Contributor

Hey @Khongchai,
Awesome work discovering the issue, could you update the refetch key issue that you located as well here?

@@ -66,7 +66,7 @@ export const useUnreadCount = ({ onSuccess, ...restOptions }: UseQueryOptions<IC
);

return () => {
socket.off(WebSocketEventEnum.UNSEEN);
socket.off(WebSocketEventEnum.UNREAD);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in line 78 we would need to update to:

enabled: isSessionInitialized && fetchingStrategy.fetchUnreadCount

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'll add this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@p-fernandez I've updated the condition. But I needed to add a couple of things more because the fetchingStrategy interface was missing the fetchUnreadCount key.

For the default value, I set it to true so that existing code won't break (it was using unseen's default and it was true)

@Khongchai
Copy link
Contributor Author

Hey @Khongchai, Awesome work discovering the issue, could you update the refetch key issue that you located as well here?

Hi, sorry for my late reply.

The refetch key issue, as I have mentioned in this issue. I'm not quite sure if this really is a problem. I thought it was at first, but after having looked into it further, it was just making sure the unseen value is updated.

I haven't checked Novu's code on this part, but should unseen be updated if unread is updated? I thought there was a bug, but after reading this comment, I'm not so sure

image

For example, if something is marked as read should they also be marked automatically as seen? If so, the code is already working as intended (maybe some Novu backend logic to update all read fields as seen).

If my understanding is incorrect and the refetch function was really not working as intended in some way, please let me know.

@Khongchai Khongchai force-pushed the next branch 2 times, most recently from 3032773 to 0b5d9ee Compare October 24, 2023 07:20
Copy link
Contributor

@p-fernandez p-fernandez left a comment

Choose a reason for hiding this comment

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

🌟

@p-fernandez p-fernandez merged commit c1b6289 into novuhq:next Oct 30, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants