Skip to content

regression(ui-voip): Switching between alternate voice call views breaks widget visibility - #41700

Merged
dionisio-bot[bot] merged 2 commits into
developfrom
fix/available-view-tracker-mutation
Aug 10, 2026
Merged

regression(ui-voip): Switching between alternate voice call views breaks widget visibility#41700
dionisio-bot[bot] merged 2 commits into
developfrom
fix/available-view-tracker-mutation

Conversation

@ggazzo

@ggazzo ggazzo commented Aug 5, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Follow-up to #41616, from this review comment.

registerView / unregisterView mutated prev.currentViews inside the useState updater. Under StrictMode — which the app runs in (apps/meteor/client/startup/appRoot.tsx) — React calls state updaters twice to surface impure ones, and the result of the second call is the one that lands:

  1. first call: prev.currentViews.add(view), returns a new object with a fresh filteredViews;
  2. second call: prev.currentViews.has(view) is now true because of the mutation, so it bails out and returns prev.

State keeps the old object, filteredViews never changes, and consumers reading currentViews (the filtered set) never see the view. So in development registerView('popout') / registerView('widget') were effectively no-ops, and unregisterView had the mirrored problem: the view stayed in the filtered set after the first call deleted it from the raw one.

The updater now copies the set instead of mutating it, and both fields are built by a single withFilteredViews helper so the raw and filtered sets can't drift.

Also removes the comment asking consumers to build a new Set before using it in a useEffect: the exposed set already gets a new identity whenever its contents change, and a new Set(...) on the consumer side would change identity on every render, firing the effect regardless of whether anything changed.

Issue(s)

DMVPR-26

Steps to test or reproduce

Covered by the new useAvailableViewTracker.spec.ts, which renders the hook inside StrictMode. Against the previous implementation 2 of its 3 cases fail.

Manually, with a call ongoing:

  1. Open the call in the popout window and close it again — both transitions work.
  2. Open the room where the call is happening: the widget hides while the room view is registered and comes back when it unregisters.

Further comments

The third test asserts identity stability (same set when nothing changed, new set when it does), since MediaCallInstanceProvider puts currentViews in a useMemo dependency list — a set rebuilt on every update would rebuild the whole context value.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved view tracking reliability in React StrictMode.
    • Prevented duplicate registrations and missing unregistrations from causing unnecessary updates.
    • Ensured the widget hides correctly when the room view is registered.
    • Preserved view state consistency when available views do not change.
  • Tests

    • Added coverage for registration, unregistration, widget visibility, and state reference behavior.

registerView/unregisterView mutated prev.currentViews inside the state
updater. StrictMode calls updaters twice, so the second call saw the
already mutated set, bailed out with prev and the filtered set consumers
read never changed - registering or unregistering a view was a no-op in
development.
@dionisio-bot

dionisio-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ad42a4a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

useAvailableViewTracker now derives filtered views through a shared helper and updates view sets immutably. Tests cover StrictMode registration, widget visibility, and currentViews reference identity.

Changes

View tracker state

Layer / File(s) Summary
Immutable view tracking
packages/ui-voip/src/providers/useAvailableViewTracker.ts, packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
The tracker copies Set instances for registration and unregistration changes. Duplicate registrations and absent unregistrations preserve the existing state. Tests cover StrictMode behavior, widget visibility, and reference identity.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: type: bug

Suggested reviewers: gabriellsh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the regression and its impact on widget visibility when switching between alternate voice call views.

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.74%. Comparing base (692be5e) to head (ad42a4a).
⚠️ Report is 14 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41700      +/-   ##
===========================================
+ Coverage    68.64%   68.74%   +0.09%     
===========================================
  Files         4164     4166       +2     
  Lines       158957   159384     +427     
  Branches     28160    28300     +140     
===========================================
+ Hits        109113   109562     +449     
+ Misses       44678    44661      -17     
+ Partials      5166     5161       -5     
Flag Coverage Δ
e2e 58.96% <ø> (+0.08%) ⬆️
e2e-api 45.76% <ø> (+0.01%) ⬆️
unit 70.64% <88.88%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gabriellsh gabriellsh changed the title fix(ui-voip): stop mutating the tracked view set regression(ui-voip): Switching between alternate voice call views breaks widget visibility Aug 10, 2026
@gabriellsh gabriellsh added this to the 8.8.0 milestone Aug 10, 2026
@gabriellsh gabriellsh added the stat: QA assured Means it has been tested and approved by a company insider label Aug 10, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 10, 2026
@gabriellsh
gabriellsh marked this pull request as ready for review August 10, 2026 16:48

@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

🧹 Nitpick comments (1)
packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts (1)

30-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the absent-view unregistration no-op.

The test verifies duplicate registration. It does not verify that unregisterView preserves the exposed Set reference when the view is absent. A regression that recreates the set in that branch will pass this test.

Proposed test addition
 		act(() => result.current.registerView('popout'));
 		expect(result.current.currentViews).toBe(views);
 
+		act(() => result.current.unregisterView('widget'));
+		expect(result.current.currentViews).toBe(views);
+
 		act(() => result.current.registerView('room'));
 		expect(result.current.currentViews).not.toBe(views);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts` around lines
30 - 40, Extend the test for useAvailableViewTracker to cover unregistering a
view that is not registered. Capture currentViews, call unregisterView with an
absent view, and assert currentViews remains the same Set reference; keep the
existing duplicate-registration and changed-view assertions intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ui-voip/src/providers/useAvailableViewTracker.ts`:
- Line 28: Remove the implementation comment in useAvailableViewTracker, leaving
the surrounding updater logic unchanged. Preserve the rationale only through the
existing test name or change record, if applicable.

---

Nitpick comments:
In `@packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts`:
- Around line 30-40: Extend the test for useAvailableViewTracker to cover
unregistering a view that is not registered. Capture currentViews, call
unregisterView with an absent view, and assert currentViews remains the same Set
reference; keep the existing duplicate-registration and changed-view assertions
intact.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a611c945-6f40-4e8e-b9ea-c43c8c2f4fe7

📥 Commits

Reviewing files that changed from the base of the PR and between 692be5e and ad42a4a.

📒 Files selected for processing (2)
  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
  • packages/ui-voip/src/providers/useAvailableViewTracker.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (13)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 🚢 Build Docker (amd64, account-service, presence-service, omnichannel-transcript-service, fips)
  • GitHub Check: 🚢 Build Docker (amd64, authorization-service, queue-worker-service, ddp-streamer-service, cove...
  • GitHub Check: 🚢 Build Docker (arm64, authorization-service, queue-worker-service, ddp-streamer-service, cove...
  • GitHub Check: 🚢 Build Docker (arm64, rocketchat, coverage)
  • GitHub Check: 🚢 Build Docker (amd64, authorization-service, queue-worker-service, ddp-streamer-service, fips)
  • GitHub Check: 🚢 Build Docker (amd64, account-service, presence-service, omnichannel-transcript-service, cove...
  • GitHub Check: 🚢 Build Docker (arm64, account-service, presence-service, omnichannel-transcript-service, cove...
  • GitHub Check: 🚢 Build Docker (amd64, rocketchat, fips)
  • GitHub Check: 🚢 Build Docker (amd64, rocketchat, coverage)
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: 🔎 Code Check / Code Lint
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
  • packages/ui-voip/src/providers/useAvailableViewTracker.ts
**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use .spec.ts extension for test files (e.g., login.spec.ts)

Files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
packages/**

📄 CodeRabbit inference engine (CLAUDE.md)

Shared libraries belong in packages/, while other services belong in apps/ and ee/.

Files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
  • packages/ui-voip/src/providers/useAvailableViewTracker.ts
🧠 Learnings (6)
📚 Learning: 2025-12-10T21:00:43.645Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:43.645Z
Learning: Adopt the monorepo-wide Jest testMatch pattern: <rootDir>/src/**/*.spec.{ts,js,mjs} (represented here as '**/src/**/*.spec.{ts,js,mjs}') to ensure spec files under any package's src directory are picked up consistently across all packages in the Rocket.Chat monorepo. Apply this pattern in jest.config.ts for all relevant packages to maintain uniform test discovery.

Applied to files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.

Applied to files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
  • packages/ui-voip/src/providers/useAvailableViewTracker.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
  • packages/ui-voip/src/providers/useAvailableViewTracker.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts
  • packages/ui-voip/src/providers/useAvailableViewTracker.ts
🔇 Additional comments (5)
packages/ui-voip/src/providers/useAvailableViewTracker.ts (3)

16-25: LGTM!


27-27: LGTM!

Also applies to: 29-30


32-42: LGTM!

packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts (2)

1-28: LGTM!


41-42: LGTM!

Comment thread packages/ui-voip/src/providers/useAvailableViewTracker.ts

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Re-trigger cubic

@gabriellsh gabriellsh removed this from the 8.8.0 milestone Aug 10, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Aug 10, 2026
@gabriellsh gabriellsh added this to the 8.8.0 milestone Aug 10, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 10, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Aug 10, 2026
Merged via the queue into develop with commit 0266006 Aug 10, 2026
56 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/available-view-tracker-mutation branch August 10, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants