Skip to content

Commit 6ca4a19

Browse files
authored
Fix race condition of "not in chat" (#1652)
* Fix race condition of "not in chat" * Add comments about fetchInitialData
1 parent b942e01 commit 6ca4a19

4 files changed

Lines changed: 13 additions & 2 deletions

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
@@ -121,6 +121,7 @@ export const ChatScreen = (props: ChatScreenProps): JSX.Element => {
121121
const adapter = useAdapter();
122122

123123
useEffect(() => {
124+
// Initial data should be always fetched by the composite(or external caller) instead of the adapter
124125
adapter.fetchInitialData();
125126
}, [adapter]);
126127

packages/react-composites/src/composites/ChatComposite/adapter/AzureCommunicationChatAdapter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ export const createAzureCommunicationChatAdapter = async ({
418418
await chatClient.startRealtimeNotifications();
419419

420420
const adapter = await createAzureCommunicationChatAdapterFromClient(chatClient, chatThreadClient);
421-
await adapter.fetchInitialData();
422421

423422
return adapter;
424423
};

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ function App(): JSX.Element {
4848
}),
4949
[]
5050
);
51-
const adapter = useAzureCommunicationChatAdapter(args);
51+
const adapter = useAzureCommunicationChatAdapter(args, async (adapter) => {
52+
// fetch initial data before we render the component to avoid flaky test (time gap between header and participant list)
53+
await adapter.fetchInitialData();
54+
return adapter;
55+
});
5256

5357
React.useEffect(() => {
5458
if (adapter && uploadedFiles.length) {

0 commit comments

Comments
 (0)