Skip to content

Commit 48acd77

Browse files
authored
Fix race condition of "not in chat" (#1652)
* Fix race condition of "not in chat" * Add comments about fetchInitialData
1 parent 7cd8fd7 commit 48acd77

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix race condition of \"not in chat\"",
4+
"packageName": "@internal/react-composites",
5+
"email": "jiangnanhello@live.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-composites/src/composites/ChatComposite/ChatScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const ChatScreen = (props: ChatScreenProps): JSX.Element => {
115115
const adapter = useAdapter();
116116

117117
useEffect(() => {
118+
// Initial data should be always fetched by the composite(or external caller) instead of the adapter
118119
adapter.fetchInitialData();
119120
}, [adapter]);
120121

packages/react-composites/tests/browser/chat/app/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ function App(): JSX.Element {
3939
}),
4040
[]
4141
);
42-
const adapter = useAzureCommunicationChatAdapter(args);
42+
const adapter = useAzureCommunicationChatAdapter(args, async (adapter) => {
43+
// fetch initial data before we render the component to avoid flaky test (time gap between header and participant list)
44+
await adapter.fetchInitialData();
45+
return adapter;
46+
});
4347

4448
return (
4549
<>

0 commit comments

Comments
 (0)