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

!fix: track DOM elements in useChatMessagesDomElements with pagination #113

Merged
merged 5 commits into from
Oct 4, 2024

Conversation

Arthurk12
Copy link
Collaborator

@Arthurk12 Arthurk12 commented Sep 12, 2024

What does this PR do?

The useChatMessagesDomElements hook was designed to expect all DOM elements from the rendered chat messages to be sent in a single event. However, due to the pagination mechanism in the bbb-core, only messages from the same page are sent together, which caused DOM elements from the last rendered page to overwrite those from previous pages.

This PR introduces support for pagination when storing DOM elements, ensuring that elements from different pages do not overwrite each other. It also includes a cleanup mechanism to remove stored DOM elements when a page is unmounted (due to pagination rolling or chat toggling). This ensures that only valid elements are stored and prevents the list from growing indefinitely.

Additionally, the hook's internal state management has been updated and the filtering for the requested message IDs has been moved to the render function to ensure that the returned DOM elements are correctly updated when message IDs passed via props change.

Breaking change: Modified the structure of data exchanged in window events UpdatedEventDetailsForChatMessageDomElements.

Closes Issue(s)

Closes #111

Note for reviewer

  • When toggling the chat very frequently, the issue may still occur. Based on my investigation, the problem appears to originate from the useLoadedChatMessages hook, which is not returning all loaded message IDs in such cases and should be addressed in a separate issue/PR.
  • The recommended way to test this PR is to use a plugin(such as this sample) that utilizes the message IDs returned from useLoadedChatMessagesand then requests some of those IDs to useChatMessagesDomElements.
  • Ensure that useLoadedChatMessages is returning all IDs correctly.

More

Relate bbb core PR: bigbluebutton/bigbluebutton#21176

Renamed the state for clarity, as it stores an array of DOM elements.
Set the initial value of the state `domElements` to an empty array for
consistency with its declared type. This ensures the hook returns a more
appropriate value(an empty array) when no message IDs are passed.
The `useChatMessagesDomElements` hook was expecting all DOM elements from
the rendered chat messages to be sent in a single event. However, due to
the pagination mechanism in the bbb-core, only messages from the same
page are sent together, which caused DOM elements from the last rendered
page to overwrite those from previous pages.

This commit adds support for pagination when storing DOM elements,
ensuring that elements from different pages do not overwrite each other.
It also includes a cleanup mechanism to remove stored DOM elements when
a page is unmounted (due to pagination rolling or chat toggling). This
ensures that only valid elements are stored and prevents the list from
growing indefinitely.

Additionally, the hook's internal state management has been updated and
the filtering for the requested message IDs has been moved to the render
function to ensure that the returned DOM elements are correctly updated
when message IDs passed via props change.
Removes the `messageIdsState` as the hook already reacts to the message
IDs passed via props, making the internal state redundant.
Checks whether the page is valid before updating state. Also, fixes a
state update that was not using the proper set state function.
Copy link
Member

@TiagoJacobs TiagoJacobs left a comment

Choose a reason for hiding this comment

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

This change seems to break the samples using the useChatMessageDomElements.

Can you please double check if they are working, and add evidences to PR?

@Arthurk12
Copy link
Collaborator Author

Actually, the PR does not break the examples using the useChatMessagesDomElements hook, as the function signature remains unchanged.

@Arthurk12 Arthurk12 requested a review from TiagoJacobs October 3, 2024 19:44
@TiagoJacobs TiagoJacobs merged commit 66b68ff into bigbluebutton:main Oct 4, 2024
3 checks passed
@TiagoJacobs
Copy link
Member

published in [email protected] !

Arthurk12 added a commit to Arthurk12/bigbluebutton that referenced this pull request Oct 7, 2024
Updates the plugins SDK to version 0.0.64 based on the discussion in
pull request bigbluebutton#113:
bigbluebutton/bigbluebutton-html-plugin-sdk#113 (comment)
Arthurk12 added a commit to Arthurk12/bigbluebutton that referenced this pull request Oct 7, 2024
Updates the plugins SDK to version 0.0.64 based on the discussion in
pull request:
bigbluebutton/bigbluebutton-html-plugin-sdk#113 (comment)
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.

useChatMessageDomElements not returning messages from other chat pages
2 participants