[FIX] VOIP CallContext snapshot infinite loop (#25947)

<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
The application was crashing due to an error on the `useCallerInfo()` hook.
The error was: 
![image](https://user-images.githubusercontent.com/20212776/174823914-4832e5dd-c91a-4ae4-9d1f-1b960bcd372c.png)
![image](https://user-images.githubusercontent.com/20212776/174823982-cb543fe0-663f-4530-bb94-0720653ca897.png)

To prevent this issue to happen it was added a cached and out-of-scope snapshot variable to the hook using `useSyncExternalStore`

<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce

1. Open rocket.chat server
2. Enable Omnichannel 
3. Enable Voip
4. Refresh de page

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->
pull/25950/head
Hugo Costa 4 years ago committed by GitHub
parent 63d4e30f0e
commit dfd1d77674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      apps/meteor/client/contexts/CallContext.ts
  2. 2
      apps/meteor/package.json
  3. 2
      packages/ui-contexts/package.json
  4. 12
      yarn.lock

@ -62,10 +62,16 @@ export const useIsCallEnabled = (): boolean => {
return enabled;
};
let callerInfo: VoIpCallerInfo;
export const useIsCallReady = (): boolean => {
const { ready } = useContext(CallContext);
const context = useContext(CallContext);
if (isCallContextReady(context)) {
callerInfo = context.voipClient.callerInfo;
}
return Boolean(ready);
return !!context.ready;
};
export const useIsCallError = (): boolean => {
@ -99,7 +105,10 @@ export const useCallerInfo = (): VoIpCallerInfo => {
},
[voipClient],
);
return useSyncExternalStore(subscribe, (): VoIpCallerInfo => voipClient.callerInfo);
const getSnapshot = (): VoIpCallerInfo => callerInfo;
return useSyncExternalStore(subscribe, getSnapshot);
};
export const useCallCreateRoom = (): CallContextReady['createRoom'] => {

@ -197,7 +197,7 @@
"@rocket.chat/forked-matrix-appservice-bridge": "^4.0.1",
"@rocket.chat/forked-matrix-bot-sdk": "^0.6.0-beta.2",
"@rocket.chat/fuselage": "0.32.0-dev.49",
"@rocket.chat/fuselage-hooks": "~0.31.14-dev.7",
"@rocket.chat/fuselage-hooks": "~0.31.14-dev.9",
"@rocket.chat/fuselage-polyfills": "~0.31.12",
"@rocket.chat/fuselage-toastbar": "^0.32.0-dev.22",
"@rocket.chat/fuselage-tokens": "~0.31.12",

@ -5,7 +5,7 @@
"devDependencies": {
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/emitter": "^0.31.11",
"@rocket.chat/fuselage-hooks": "~0.31.14-dev.7",
"@rocket.chat/fuselage-hooks": "~0.31.14-dev.9",
"@rocket.chat/rest-typings": "workspace:^",
"@types/jest": "^27.4.1",
"@types/mongodb": "~3.6.10",

@ -3529,15 +3529,15 @@ __metadata:
languageName: node
linkType: hard
"@rocket.chat/fuselage-hooks@npm:~0.31.14-dev.7":
version: 0.31.14-dev.7
resolution: "@rocket.chat/fuselage-hooks@npm:0.31.14-dev.7"
"@rocket.chat/fuselage-hooks@npm:~0.31.14-dev.9":
version: 0.31.14-dev.9
resolution: "@rocket.chat/fuselage-hooks@npm:0.31.14-dev.9"
dependencies:
use-sync-external-store: ~1.2.0
peerDependencies:
"@rocket.chat/fuselage-tokens": "*"
react: ^17.0.2
checksum: ad2a1a61189d694e5e70ab73dfc20a7bea7ad0686be97993b24c6053b5cfa027e6b70690b75b5e9c1e8712a2b41f7d031a416c5e6781e9c4b31b5c0a40529ea0
checksum: fa79c8c8a5b56d0c5ccd2118735a6eef5aaf99f1392161d90e72da4dc0cd1dc9007387df71ab428545f72a3c5c8c1648c086078724cb4698ec05044a0462e0b6
languageName: node
linkType: hard
@ -3819,7 +3819,7 @@ __metadata:
"@rocket.chat/forked-matrix-appservice-bridge": ^4.0.1
"@rocket.chat/forked-matrix-bot-sdk": ^0.6.0-beta.2
"@rocket.chat/fuselage": 0.32.0-dev.49
"@rocket.chat/fuselage-hooks": ~0.31.14-dev.7
"@rocket.chat/fuselage-hooks": ~0.31.14-dev.9
"@rocket.chat/fuselage-polyfills": ~0.31.12
"@rocket.chat/fuselage-toastbar": ^0.32.0-dev.22
"@rocket.chat/fuselage-tokens": ~0.31.12
@ -4239,7 +4239,7 @@ __metadata:
dependencies:
"@rocket.chat/core-typings": "workspace:^"
"@rocket.chat/emitter": ^0.31.11
"@rocket.chat/fuselage-hooks": ~0.31.14-dev.7
"@rocket.chat/fuselage-hooks": ~0.31.14-dev.9
"@rocket.chat/rest-typings": "workspace:^"
"@types/jest": ^27.4.1
"@types/mongodb": ~3.6.10

Loading…
Cancel
Save