fix(mobile): retire launch drafts on literal marker turns

(cherry picked from commit 794e07c8dc)
This commit is contained in:
Brennan Benson
2026-08-16 12:02:57 -07:00
parent 40f4240389
commit ce409f52da
2 changed files with 37 additions and 3 deletions
@@ -123,6 +123,40 @@ describe('useMobileNativeChatDrafts launch draft', () => {
expect(state?.composerText).toBe('')
})
it('declines a launch draft when the only user turn is a literal image marker', async () => {
await mount('a')
await act(async () =>
renderer?.update(
createElement(Harness, {
tabId: 'a',
messages: [userTextMessage('m1', '[Image #1]')],
launchDraft: 'issue link'
})
)
)
expect(state?.composerText).toBe('')
})
it('retires an adopted launch draft when a literal marker turn lands', async () => {
await mount('a')
await act(async () =>
renderer?.update(createElement(Harness, { tabId: 'a', launchDraft: 'issue link' }))
)
expect(state?.composerText).toBe('issue link')
await act(async () =>
renderer?.update(
createElement(Harness, {
tabId: 'a',
messages: [userTextMessage('m1', '[Image #1]')],
launchDraft: 'issue link'
})
)
)
expect(state?.composerText).toBe('')
})
it('clears an untouched prefill once a user turn lands, keeping user edits', async () => {
await mount('a')
await act(async () =>
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useRef, type Dispatch, type SetStateAction } from 'react'
import type { NativeChatMessage } from '../../../src/shared/native-chat-types'
import { normalizedUserText } from './mobile-native-chat-draft-reconcile'
import { nativeChatUserMessageMatchText } from './mobile-native-chat-image-transcript-markers'
export type MobileNativeChatLaunchDraftSeed = {
text: string
@@ -63,7 +63,7 @@ export function useMobileNativeChatLaunchDraftSeed(args: {
}
// A user turn already in the transcript means the TUI prefill was submitted
// or deliberately cleared; decline instead of resurrecting it.
if (messages.some((message) => normalizedUserText(message) !== null)) {
if (messages.some((message) => nativeChatUserMessageMatchText(message) !== null)) {
seededLaunchDraftByKeyRef.current.set(draftKey, null)
return
}
@@ -98,7 +98,7 @@ export function useMobileNativeChatLaunchDraftSeed(args: {
if (!seeded) {
return
}
const hasUserTurn = messages.some((message) => normalizedUserText(message) !== null)
const hasUserTurn = messages.some((message) => nativeChatUserMessageMatchText(message) !== null)
if (!hasUserTurn && launchDraft?.trim()) {
return
}