Skip to content

Fix(html5): Race condition leading to an error in conditionally rendered chat hooks. - #23245

Merged
antobinary merged 4 commits into
bigbluebutton:v3.0.x-releasefrom
Tainan404:i-23243
May 23, 2025
Merged

antobinary merged 4 commits into
bigbluebutton:v3.0.x-releasefrom
Tainan404:i-23243

Conversation

@Tainan404

Copy link
Copy Markdown
Member

What does this PR do?

The error occurred because the observer wasn't functioning correctly. A condition checkedUserSettings was added around the logic that determines whether to render the Chat component 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 Chat component 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

  • Join a user and join webcam
  • Join a second user

More

Screencast.from.22-05-2025.16.25.30.webm

@coderabbitai

coderabbitai Bot commented May 22, 2025 •

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The changes shift the responsibility for checking if chat is enabled from the ChatMessageForm component to its container component, which now returns null immediately if chat is disabled, preventing the form from rendering. In the layout observer component, the logic controlling the sidebar navigation and content panel visibility has been refactored by introducing a new layoutIsReady state and splitting the previous single effect into two separate effects. These effects independently manage the sidebar panels based on chat enablement, user settings, and device type. The user settings saving logic is also adjusted to set the layoutIsReady flag after saving, avoiding repeated execution. No changes were made to the signatures of exported or public entities.

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
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent client errors and chat panel rendering when chat is disabled (#23243) ✅

Suggested reviewers

  • antonbsa
  • gustavotrott
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c403ea1 and f49ab4d.

📒 Files selected for processing (1)
  • 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/layout/observer.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)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@antobinary antobinary added this to the Release 3.0 milestone May 22, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0be42d3 and c403ea1.

📒 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 layoutIsReady state 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 isChatEnabled or layoutIsReady changes. 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

Comment on lines +265 to 277
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);
}
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ 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.

Suggested change
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.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have 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.

disableFeatures=chat leads to client errors

3 participants