From 712ddceb93c193cf3255258768f15a039ab227ac Mon Sep 17 00:00:00 2001 From: Neil Campbell Date: Thu, 19 Feb 2026 16:45:58 +0800 Subject: [PATCH] fix: correct chatAdapterOptions handling inside useAzureCommunicationChatAdapter --- .../adapter/AzureCommunicationChatAdapter.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/react-composites/src/composites/ChatComposite/adapter/AzureCommunicationChatAdapter.ts b/packages/react-composites/src/composites/ChatComposite/adapter/AzureCommunicationChatAdapter.ts index 981df4ee1e8..509d2224751 100644 --- a/packages/react-composites/src/composites/ChatComposite/adapter/AzureCommunicationChatAdapter.ts +++ b/packages/react-composites/src/composites/ChatComposite/adapter/AzureCommunicationChatAdapter.ts @@ -678,7 +678,7 @@ export const useAzureCommunicationChatAdapter = ( */ beforeDispose?: (adapter: ChatAdapter) => Promise ): ChatAdapter | undefined => { - const { credential, displayName, endpoint, threadId, userId } = args; + const { credential, displayName, endpoint, threadId, userId, chatAdapterOptions } = args; // State update needed to rerender the parent component when a new adapter is created. const [adapter, setAdapter] = useState(undefined); @@ -688,12 +688,14 @@ export const useAzureCommunicationChatAdapter = ( const afterCreateRef = useRef<((adapter: ChatAdapter) => Promise) | undefined>(undefined); const beforeDisposeRef = useRef<((adapter: ChatAdapter) => Promise) | undefined>(undefined); + const chatAdapterOptionsRef = useRef(undefined); // These refs are updated on *each* render, so that the latest values // are used in the `useEffect` closures below. // Using a Ref ensures that new values for the callbacks do not trigger the // useEffect blocks, and a new adapter creation / distruction is not triggered. afterCreateRef.current = afterCreate; beforeDisposeRef.current = beforeDispose; + chatAdapterOptionsRef.current = chatAdapterOptions; useEffect( () => { @@ -725,7 +727,8 @@ export const useAzureCommunicationChatAdapter = ( displayName, endpoint, threadId, - userId + userId, + ...(chatAdapterOptionsRef.current ? { chatAdapterOptions: chatAdapterOptionsRef.current } : undefined) }); if (afterCreateRef.current) { newAdapter = await afterCreateRef.current(newAdapter); @@ -736,7 +739,17 @@ export const useAzureCommunicationChatAdapter = ( })(); }, // Explicitly list all arguments so that caller doesn't have to memoize the `args` object. - [adapterRef, afterCreateRef, beforeDisposeRef, credential, displayName, endpoint, threadId, userId] + [ + adapterRef, + afterCreateRef, + beforeDisposeRef, + chatAdapterOptionsRef, + credential, + displayName, + endpoint, + threadId, + userId + ] ); // Dispose any existing adapter when the component unmounts.