regression(ui-voip): Switching between alternate voice call views breaks widget visibility - #41700
Conversation
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.
|
Looks like this PR is ready to merge! 🎉 |
|
Walkthrough
ChangesView tracker state
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/ui-voip/src/providers/useAvailableViewTracker.spec.ts (1)
30-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the absent-view unregistration no-op.
The test verifies duplicate registration. It does not verify that
unregisterViewpreserves the exposedSetreference 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
📒 Files selected for processing (2)
packages/ui-voip/src/providers/useAvailableViewTracker.spec.tspackages/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.tspackages/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.tsextension 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 inapps/andee/.
Files:
packages/ui-voip/src/providers/useAvailableViewTracker.spec.tspackages/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.tspackages/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.tspackages/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.tspackages/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!
Proposed changes (including videos or screenshots)
Follow-up to #41616, from this review comment.
registerView/unregisterViewmutatedprev.currentViewsinside theuseStateupdater. UnderStrictMode— 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:prev.currentViews.add(view), returns a new object with a freshfilteredViews;prev.currentViews.has(view)is nowtruebecause of the mutation, so it bails out and returnsprev.State keeps the old object,
filteredViewsnever changes, and consumers readingcurrentViews(the filtered set) never see the view. So in developmentregisterView('popout')/registerView('widget')were effectively no-ops, andunregisterViewhad 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
withFilteredViewshelper so the raw and filtered sets can't drift.Also removes the comment asking consumers to build a new
Setbefore using it in auseEffect: the exposed set already gets a new identity whenever its contents change, and anew 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 insideStrictMode. Against the previous implementation 2 of its 3 cases fail.Manually, with a call ongoing:
Further comments
The third test asserts identity stability (same set when nothing changed, new set when it does), since
MediaCallInstanceProviderputscurrentViewsin auseMemodependency list — a set rebuilt on every update would rebuild the whole context value.Summary by CodeRabbit
Bug Fixes
Tests