[Obs AI Assistant] Fix bug “Cannot set initialMessages if initialConversationId is set" (#189885)

This fixes a bug that occurs with the Insights component when clicking
"Start Chat" for a second time.

**Reproducing the bug**
- Go to any Obs alert and open the insights component
- Click "Start Chat" and a flyout with the non-persisted conversation is
opened.
- Add a new message in order to persist the conversation
- Close the flyout
- Click "Start Chat" again

```
Error: Cannot set initialMessages if initialConversationId is set
    at useConversation (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/plugin/observabilityAIAssistantApp/1.0.0/observabilityAIAssistantApp.chunk.0.js:11554:11)
    at ChatBody (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/plugin/observabilityAIAssistantApp/1.0.0/observabilityAIAssistantApp.chunk.0.js:8112:86)
    at renderWithHooks (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:358087:18)
    at mountIndeterminateComponent (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:360913:13)
    at beginWork (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:362151:16)
    at HTMLUnknownElement.callCallback (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:347047:14)
    at Object.invokeGuardedCallbackDev (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:347096:16)
    at invokeGuardedCallback (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:347158:31)
    at beginWork$1 (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:367061:7)
    at performUnitOfWork (http://localhost:5601/fix/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:365873:12)
```
This commit is contained in:
Søren Louv-Jansen 2024-08-05 17:15:27 +02:00 committed by GitHub
parent 66396cf87c
commit 888ca9be87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,6 +67,7 @@ export function NavControl({}: {}) {
useEffect(() => {
const conversationSubscription = service.conversations.predefinedConversation$.subscribe(() => {
keyRef.current = v4();
setHasBeenOpened(true);
setIsOpen(true);
});