-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ai): no more unnecessary re-renders in AIConversation (#5883)
- Loading branch information
1 parent
9ac7b8d
commit 77ac8b9
Showing
5 changed files
with
112 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@aws-amplify/ui-react-ai": patch | ||
--- | ||
|
||
fix(ai): no more unnecessary re-renders in AIConversation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/react-ai/src/components/AIConversation/AIConversationProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
|
||
import { ElementsProvider } from '@aws-amplify/ui-react-core/elements'; | ||
|
||
import { AIConversationInput, AIConversationProps } from './types'; | ||
import { defaultAIConversationDisplayTextEn } from './displayText'; | ||
import { | ||
ConversationDisplayTextProvider, | ||
SuggestedPromptProvider, | ||
ConversationInputContextProvider, | ||
AvatarsProvider, | ||
ActionsProvider, | ||
MessageVariantProvider, | ||
MessagesProvider, | ||
ControlsProvider, | ||
LoadingContextProvider, | ||
ResponseComponentsProvider, | ||
SendMessageContextProvider, | ||
} from './context'; | ||
import { AttachmentProvider } from './context/AttachmentContext'; | ||
|
||
interface AIConversationProviderProps | ||
extends AIConversationInput, | ||
AIConversationProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
export const AIConversationProvider = ({ | ||
elements, | ||
actions, | ||
suggestedPrompts, | ||
responseComponents, | ||
variant, | ||
controls, | ||
displayText, | ||
allowAttachments, | ||
messages, | ||
handleSendMessage, | ||
avatars, | ||
isLoading, | ||
children, | ||
}: AIConversationProviderProps): React.JSX.Element => { | ||
const _displayText = { | ||
...defaultAIConversationDisplayTextEn, | ||
...displayText, | ||
}; | ||
return ( | ||
<ElementsProvider elements={elements}> | ||
<ControlsProvider controls={controls}> | ||
<SuggestedPromptProvider suggestedPrompts={suggestedPrompts}> | ||
<ResponseComponentsProvider responseComponents={responseComponents}> | ||
<AttachmentProvider allowAttachments={allowAttachments}> | ||
<ConversationDisplayTextProvider {..._displayText}> | ||
<ConversationInputContextProvider> | ||
<SendMessageContextProvider | ||
handleSendMessage={handleSendMessage} | ||
> | ||
<AvatarsProvider avatars={avatars}> | ||
<ActionsProvider actions={actions}> | ||
<MessageVariantProvider variant={variant}> | ||
<MessagesProvider messages={messages}> | ||
<LoadingContextProvider isLoading={isLoading}> | ||
{children} | ||
</LoadingContextProvider> | ||
</MessagesProvider> | ||
</MessageVariantProvider> | ||
</ActionsProvider> | ||
</AvatarsProvider> | ||
</SendMessageContextProvider> | ||
</ConversationInputContextProvider> | ||
</ConversationDisplayTextProvider> | ||
</AttachmentProvider> | ||
</ResponseComponentsProvider> | ||
</SuggestedPromptProvider> | ||
</ControlsProvider> | ||
</ElementsProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 0 additions & 90 deletions
90
packages/react-ai/src/components/AIConversation/createProvider.tsx
This file was deleted.
Oops, something went wrong.