mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 21:06:22 +08:00
fix(core): missing clean up subscription (#10636)
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/utils';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/utils';
|
||||||
import type { Store } from '@blocksuite/affine/store';
|
import type { Store } from '@blocksuite/affine/store';
|
||||||
import { HelpIcon, InformationIcon } from '@blocksuite/icons/lit';
|
import { HelpIcon, InformationIcon } from '@blocksuite/icons/lit';
|
||||||
|
import { type Signal, signal } from '@preact/signals-core';
|
||||||
import { css, html, type PropertyValues } from 'lit';
|
import { css, html, type PropertyValues } from 'lit';
|
||||||
import { property, state } from 'lit/decorators.js';
|
import { property, state } from 'lit/decorators.js';
|
||||||
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
|
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
|
||||||
@@ -271,6 +272,10 @@ export class ChatPanel extends SignalWatcher(
|
|||||||
|
|
||||||
private _chatContextId: string | null | undefined = null;
|
private _chatContextId: string | null | undefined = null;
|
||||||
|
|
||||||
|
private _isOpen: Signal<boolean | undefined> = signal(false);
|
||||||
|
|
||||||
|
private _width: Signal<number | undefined> = signal(undefined);
|
||||||
|
|
||||||
private readonly _scrollToEnd = () => {
|
private readonly _scrollToEnd = () => {
|
||||||
if (!this._wheelTriggered) {
|
if (!this._wheelTriggered) {
|
||||||
this._chatMessages.value?.scrollToEnd();
|
this._chatMessages.value?.scrollToEnd();
|
||||||
@@ -306,8 +311,7 @@ export class ChatPanel extends SignalWatcher(
|
|||||||
|
|
||||||
private readonly _initPanel = async () => {
|
private readonly _initPanel = async () => {
|
||||||
try {
|
try {
|
||||||
const isOpen = !!this.appSidebarConfig.isOpen().signal.value;
|
if (!this._isOpen.value) return;
|
||||||
if (!isOpen) return;
|
|
||||||
|
|
||||||
const userId = (await AIProvider.userInfo)?.id;
|
const userId = (await AIProvider.userInfo)?.id;
|
||||||
if (!userId) return;
|
if (!userId) return;
|
||||||
@@ -383,14 +387,6 @@ export class ChatPanel extends SignalWatcher(
|
|||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._disposables.add(
|
|
||||||
this.appSidebarConfig.isOpen().signal.subscribe(isOpen => {
|
|
||||||
if (isOpen && this.isLoading) {
|
|
||||||
this._initPanel().catch(console.error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
@@ -422,6 +418,22 @@ export class ChatPanel extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isOpen = this.appSidebarConfig.isOpen();
|
||||||
|
this._isOpen = isOpen.signal;
|
||||||
|
this._disposables.add(isOpen.cleanup);
|
||||||
|
|
||||||
|
const width = this.appSidebarConfig.getWidth();
|
||||||
|
this._width = width.signal;
|
||||||
|
this._disposables.add(width.cleanup);
|
||||||
|
|
||||||
|
this._disposables.add(
|
||||||
|
this._isOpen.subscribe(isOpen => {
|
||||||
|
if (isOpen && this.isLoading) {
|
||||||
|
this._initPanel().catch(console.error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateContext = (context: Partial<ChatContextValue>) => {
|
updateContext = (context: Partial<ChatContextValue>) => {
|
||||||
@@ -440,10 +452,9 @@ export class ChatPanel extends SignalWatcher(
|
|||||||
};
|
};
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
const panelWidth = this.appSidebarConfig.getWidth().signal.value;
|
const width = this._width.value || 0;
|
||||||
const style = styleMap({
|
const style = styleMap({
|
||||||
padding:
|
padding: width > 540 ? '8px 24px 0 24px' : '8px 12px 0 12px',
|
||||||
panelWidth && panelWidth > 540 ? '8px 24px 0 24px' : '8px 12px 0 12px',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return html`<div class="chat-panel-container" style=${style}>
|
return html`<div class="chat-panel-container" style=${style}>
|
||||||
|
|||||||
@@ -70,8 +70,10 @@ async function createSessionMessage({
|
|||||||
sessionId: providedSessionId,
|
sessionId: providedSessionId,
|
||||||
attachments,
|
attachments,
|
||||||
params,
|
params,
|
||||||
retry = false,
|
}: TextToTextOptions): Promise<{
|
||||||
}: TextToTextOptions) {
|
sessionId: string;
|
||||||
|
messageId: string;
|
||||||
|
}> {
|
||||||
if (!promptName && !providedSessionId) {
|
if (!promptName && !providedSessionId) {
|
||||||
throw new Error('promptName or sessionId is required');
|
throw new Error('promptName or sessionId is required');
|
||||||
}
|
}
|
||||||
@@ -107,10 +109,6 @@ async function createSessionMessage({
|
|||||||
)
|
)
|
||||||
).filter(Boolean) as File[];
|
).filter(Boolean) as File[];
|
||||||
}
|
}
|
||||||
if (retry)
|
|
||||||
return {
|
|
||||||
sessionId,
|
|
||||||
};
|
|
||||||
|
|
||||||
const messageId = await client.createMessage(options);
|
const messageId = await client.createMessage(options);
|
||||||
return {
|
return {
|
||||||
@@ -157,7 +155,6 @@ export function textToText({
|
|||||||
attachments,
|
attachments,
|
||||||
params,
|
params,
|
||||||
sessionId,
|
sessionId,
|
||||||
retry,
|
|
||||||
});
|
});
|
||||||
_sessionId = message.sessionId;
|
_sessionId = message.sessionId;
|
||||||
_messageId = message.messageId;
|
_messageId = message.messageId;
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
|||||||
chatPanelRef.current = new ChatPanel();
|
chatPanelRef.current = new ChatPanel();
|
||||||
chatPanelRef.current.host = editor.host;
|
chatPanelRef.current.host = editor.host;
|
||||||
chatPanelRef.current.doc = editor.doc;
|
chatPanelRef.current.doc = editor.doc;
|
||||||
containerRef.current?.append(chatPanelRef.current);
|
|
||||||
const searchService = framework.get(AINetworkSearchService);
|
const searchService = framework.get(AINetworkSearchService);
|
||||||
const docDisplayMetaService = framework.get(DocDisplayMetaService);
|
const docDisplayMetaService = framework.get(DocDisplayMetaService);
|
||||||
const workspaceService = framework.get(WorkspaceService);
|
const workspaceService = framework.get(WorkspaceService);
|
||||||
@@ -101,6 +100,7 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
|||||||
SpecProvider._.getSpec('preview:page')
|
SpecProvider._.getSpec('preview:page')
|
||||||
);
|
);
|
||||||
chatPanelRef.current.previewSpecBuilder = previewSpecBuilder;
|
chatPanelRef.current.previewSpecBuilder = previewSpecBuilder;
|
||||||
|
containerRef.current?.append(chatPanelRef.current);
|
||||||
} else {
|
} else {
|
||||||
chatPanelRef.current.host = editor.host;
|
chatPanelRef.current.host = editor.host;
|
||||||
chatPanelRef.current.doc = editor.doc;
|
chatPanelRef.current.doc = editor.doc;
|
||||||
|
|||||||
Reference in New Issue
Block a user