Skip to content

Commit 3842090

Browse files
committed
fix(editor): prevent double unmount crash when publishing with agent panel open
Initialize lastEmittedJson from the initial richContent prop so the editorKey watcher doesn't spuriously fire on mount, which caused a second unmount/remount cycle that crashed Vue's Teleport teardown. Made-with: Cursor
1 parent 3335adc commit 3842090

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/components/editor/rich/agent-chat/composables/use-session-manager.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function useSessionManager(options: SessionManagerOptions) {
4848
let sessionEpoch = 0
4949
let pendingSync: { sessionId: string; cancel: () => void } | null = null
5050
let diffSyncTimer: ReturnType<typeof setTimeout> | null = null
51+
let titlePollTimer: ReturnType<typeof setTimeout> | null = null
5152

5253
async function loadSessions() {
5354
const id = refId.value
@@ -172,7 +173,18 @@ export function useSessionManager(options: SessionManagerOptions) {
172173
const bubbles = store.getState().bubbles
173174
if (bubbles.length === 0) return
174175
const messages = bubbles as unknown as Record<string, unknown>[]
175-
aiAgentApi.replaceMessages(sessionId, messages).catch(() => {})
176+
aiAgentApi
177+
.replaceMessages(sessionId, messages)
178+
.then(() => {
179+
const meta = sessions.value.find((s) => s.id === sessionId)
180+
if (meta && !meta.title && !titlePollTimer) {
181+
titlePollTimer = setTimeout(() => {
182+
titlePollTimer = null
183+
loadSessions()
184+
}, 6000)
185+
}
186+
})
187+
.catch(() => {})
176188
}
177189

178190
function scheduleSyncMessages() {
@@ -286,6 +298,7 @@ export function useSessionManager(options: SessionManagerOptions) {
286298
flushPendingSync()
287299
unsubscribe()
288300
if (diffSyncTimer) clearTimeout(diffSyncTimer)
301+
if (titlePollTimer) clearTimeout(titlePollTimer)
289302
})
290303

291304
watch(

src/components/editor/write-editor/RichWriteEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export const RichWriteEditor = defineComponent({
9393
const hasContent = computed(() => currentText.value.trim().length > 0)
9494

9595
const editorKey = ref(0)
96-
let lastEmittedJson = ''
96+
let lastEmittedJson = props.richContent
97+
? JSON.stringify(props.richContent)
98+
: ''
9799

98100
watch(
99101
() => props.richContent,

0 commit comments

Comments
 (0)