Repository navigation
Fix(html5): Race condition leading to an error in conditionally rendered chat hooks. - #23245
Conversation
|
""" WalkthroughThe changes shift the responsibility for checking if chat is enabled from the Sequence Diagram(s)sequenceDiagram
participant User
participant ChatMessageFormContainer
participant ChatMessageForm
User->>ChatMessageFormContainer: Render
ChatMessageFormContainer->>ChatMessageFormContainer: Check if chat is enabled
alt Chat enabled
ChatMessageFormContainer->>ChatMessageForm: Render
else Chat disabled
ChatMessageFormContainer-->>User: Render nothing (null)
end
Assessment against linked issues
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
bigbluebutton-html5/imports/ui/components/chat/chat-graphql/chat-message-form/component.tsx(2 hunks)bigbluebutton-html5/imports/ui/components/layout/observer.tsx(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- bigbluebutton-html5/imports/ui/components/chat/chat-graphql/chat-message-form/component.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: build-package (others)
- GitHub Check: build-package (bbb-html5)
- GitHub Check: build-package (bbb-graphql-server)
- GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (3)
bigbluebutton-html5/imports/ui/components/layout/observer.tsx (3)
37-37: Good addition of state to manage layout readiness.The introduction of
layoutIsReadystate effectively decouples the layout readiness from the one-time user settings check, which should resolve the race condition mentioned in the PR objectives.
221-243: Well-structured chat control logic with proper separation of concerns.The chat control logic is now properly isolated and will re-evaluate when either
isChatEnabledorlayoutIsReadychanges. This addresses the core issue where the observer would only evaluate the chat rendering condition once.The logic correctly:
- Opens chat sidebar when both chat is enabled and user settings allow it
- Closes sidebar content when conditions aren't met
- Dispatches all necessary actions for proper state management
245-263: Sidebar navigation logic properly separated and conditional.The sidebar navigation control is well-implemented with appropriate conditions:
- Only runs when layout is ready and no content panel is active
- Respects user settings for showing participants on login
- Handles device-specific logic (excluding phones)
- Properly manages both navigation and content sidebar states
| useEffect(() => { | ||
| if (Session.equals('layoutReady', true)) { | ||
| if (!checkedUserSettings.current) { | ||
| const Settings = getSettingsSingletonInstance(); | ||
| Settings.save(setLocalSettings); | ||
|
|
||
| if (getFromUserSettings('bbb_show_participants_on_login', window.meetingClientSettings.public.layout.showParticipantsOnLogin) && !deviceInfo.isPhone) { | ||
| if (isChatEnabled && getFromUserSettings('bbb_show_public_chat_on_login', !window.meetingClientSettings.public.chat.startClosed)) { | ||
| const PUBLIC_CHAT_ID = window.meetingClientSettings.public.chat.public_group_id; | ||
|
|
||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN, | ||
| value: true, | ||
| }); | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN, | ||
| value: true, | ||
| }); | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL, | ||
| value: PANELS.CHAT, | ||
| }); | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_ID_CHAT_OPEN, | ||
| value: PUBLIC_CHAT_ID, | ||
| }); | ||
| } else { | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN, | ||
| value: true, | ||
| }); | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN, | ||
| value: false, | ||
| }); | ||
| } | ||
| } else { | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN, | ||
| value: false, | ||
| }); | ||
| layoutContextDispatch({ | ||
| type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN, | ||
| value: false, | ||
| }); | ||
| } | ||
|
|
||
| checkedUserSettings.current = true; | ||
| } | ||
|
|
||
| if (!layoutIsReady) { | ||
| setLayoutIsReady(true); | ||
| } | ||
| } | ||
| }); |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix performance issue: Add dependency array to useEffect.
The useEffect hook lacks a dependency array, causing it to run on every render instead of only when dependencies change. This could lead to performance issues and unnecessary re-executions.
useEffect(() => {
if (Session.equals('layoutReady', true)) {
if (!checkedUserSettings.current) {
const Settings = getSettingsSingletonInstance();
Settings.save(setLocalSettings);
checkedUserSettings.current = true;
}
if (!layoutIsReady) {
setLayoutIsReady(true);
}
}
- });
+ }, [layoutIsReady, setLocalSettings]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| useEffect(() => { | |
| if (Session.equals('layoutReady', true)) { | |
| if (!checkedUserSettings.current) { | |
| const Settings = getSettingsSingletonInstance(); | |
| Settings.save(setLocalSettings); | |
| if (getFromUserSettings('bbb_show_participants_on_login', window.meetingClientSettings.public.layout.showParticipantsOnLogin) && !deviceInfo.isPhone) { | |
| if (isChatEnabled && getFromUserSettings('bbb_show_public_chat_on_login', !window.meetingClientSettings.public.chat.startClosed)) { | |
| const PUBLIC_CHAT_ID = window.meetingClientSettings.public.chat.public_group_id; | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN, | |
| value: true, | |
| }); | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN, | |
| value: true, | |
| }); | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL, | |
| value: PANELS.CHAT, | |
| }); | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_ID_CHAT_OPEN, | |
| value: PUBLIC_CHAT_ID, | |
| }); | |
| } else { | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN, | |
| value: true, | |
| }); | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN, | |
| value: false, | |
| }); | |
| } | |
| } else { | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN, | |
| value: false, | |
| }); | |
| layoutContextDispatch({ | |
| type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN, | |
| value: false, | |
| }); | |
| } | |
| checkedUserSettings.current = true; | |
| } | |
| if (!layoutIsReady) { | |
| setLayoutIsReady(true); | |
| } | |
| } | |
| }); | |
| useEffect(() => { | |
| if (Session.equals('layoutReady', true)) { | |
| if (!checkedUserSettings.current) { | |
| const Settings = getSettingsSingletonInstance(); | |
| Settings.save(setLocalSettings); | |
| checkedUserSettings.current = true; | |
| } | |
| if (!layoutIsReady) { | |
| setLayoutIsReady(true); | |
| } | |
| } | |
| }, [layoutIsReady, setLocalSettings]); |
🤖 Prompt for AI Agents
In bigbluebutton-html5/imports/ui/components/layout/observer.tsx around lines
265 to 277, the useEffect hook is missing a dependency array, causing it to run
on every render and potentially degrade performance. Add an appropriate
dependency array to the useEffect call to ensure it only runs when relevant
dependencies like 'layoutIsReady' or any other used variables change.
|
Automated tests Summary✅ All the CI tests have passed! |



What does this PR do?
The error occurred because the observer wasn't functioning correctly. A condition
checkedUserSettingswas added around the logic that determines whether to render theChatcomponent based on disabled features. This condition was originally intended to ensure the settings singleton was loaded only once.However, it unintentionally caused the observer to check whether the
Chatcomponent should be rendered only a single time. Splitting this logic into two separate conditions resolved the issue by allowing proper re-evaluation of both the settings and the chat render condition.Closes Issue(s)
Closes #23243
How to test
More
Screencast.from.22-05-2025.16.25.30.webm