@@ -580,12 +580,11 @@ describe("PreviewView navigation", () => {
580580 createdAt : "2026-09-05T00:00:00.000Z" ,
581581 } ;
582582 const onSendAnnotation = vi . fn ( ) ;
583- mocks . pickElement . mockResolvedValue ( { annotation, submission : "send" } ) ;
584- let finishCapture : ( ( ) => void ) | undefined ;
585- mocks . capturePreviewAnnotationScreenshot . mockImplementationOnce (
583+ let submitPick : ( ( ) => void ) | undefined ;
584+ mocks . pickElement . mockImplementationOnce (
586585 ( ) =>
587586 new Promise ( ( resolve ) => {
588- finishCapture = ( ) => resolve ( { status : "none " } ) ;
587+ submitPick = ( ) => resolve ( { annotation , submission : "send " } ) ;
589588 } ) ,
590589 ) ;
591590 const document = installTestDom ( ) ;
@@ -602,19 +601,20 @@ describe("PreviewView navigation", () => {
602601 try {
603602 await act ( async ( ) => root . render ( view ( ) ) ) ;
604603 await act ( async ( ) => mocks . toggleAnnotation ?.( ) ) ;
605- expect ( finishCapture ) . toBeDefined ( ) ;
604+ expect ( submitPick ) . toBeDefined ( ) ;
606605 expect ( mocks . setAnnotationSendEnabled ) . toHaveBeenLastCalledWith ( TEST_RUNTIME_TAB_ID , true ) ;
607606
608607 mocks . readEnvironmentScope . mockImplementation (
609608 ( environmentId ?: unknown ) => environmentId !== TEST_THREAD_REF . environmentId ,
610609 ) ;
611610 await act ( async ( ) => root . render ( view ( ) ) ) ;
612611 expect ( mocks . setAnnotationSendEnabled ) . toHaveBeenLastCalledWith ( TEST_RUNTIME_TAB_ID , false ) ;
613- await act ( async ( ) => finishCapture ! ( ) ) ;
612+ await act ( async ( ) => submitPick ! ( ) ) ;
614613 expect ( mocks . addPreviewAnnotation ) . toHaveBeenCalledWith ( TEST_THREAD_REF , annotation ) ;
615614 expect ( onSendAnnotation ) . not . toHaveBeenCalled ( ) ;
616615
617616 mocks . readEnvironmentScope . mockReturnValue ( true ) ;
617+ mocks . pickElement . mockResolvedValue ( { annotation, submission : "send" } ) ;
618618 await act ( async ( ) => root . render ( view ( ) ) ) ;
619619 await act ( async ( ) => mocks . toggleAnnotation ?.( ) ) ;
620620 expect ( mocks . setAnnotationSendEnabled ) . toHaveBeenLastCalledWith ( TEST_RUNTIME_TAB_ID , true ) ;
@@ -625,6 +625,48 @@ describe("PreviewView navigation", () => {
625625 }
626626 } ) ;
627627
628+ it ( "keeps a submitted annotation when the picker is toggled during capture" , async ( ) => {
629+ const annotation = {
630+ id : "annotation-submitted" ,
631+ pageUrl : "https://example.com/dashboard" ,
632+ pageTitle : "Dashboard" ,
633+ comment : "Tighten this spacing" ,
634+ elements : [ ] ,
635+ regions : [ ] ,
636+ strokes : [ ] ,
637+ styleChanges : [ ] ,
638+ screenshot : null ,
639+ createdAt : "2026-09-05T00:00:00.000Z" ,
640+ } ;
641+ mocks . pickElement . mockResolvedValue ( { annotation, submission : "attach" } ) ;
642+ let finishCapture : ( ( ) => void ) | undefined ;
643+ mocks . capturePreviewAnnotationScreenshot . mockImplementationOnce (
644+ ( ) =>
645+ new Promise ( ( resolve ) => {
646+ finishCapture = ( ) => resolve ( { status : "none" } ) ;
647+ } ) ,
648+ ) ;
649+ const document = installTestDom ( ) ;
650+ const { createRoot } = await import ( "react-dom/client" ) ;
651+ const root = createRoot ( document . createElement ( "div" ) as unknown as Element ) ;
652+ try {
653+ await act ( async ( ) =>
654+ root . render ( < PreviewView threadRef = { TEST_THREAD_REF } tabId = "tab-1" visible /> ) ,
655+ ) ;
656+ await act ( async ( ) => mocks . toggleAnnotation ?.( ) ) ;
657+ expect ( finishCapture ) . toBeDefined ( ) ;
658+ // The pick is no longer active once the guest has submitted, so this
659+ // starts a new pick instead of cancelling the submitted one.
660+ await act ( async ( ) => mocks . toggleAnnotation ?.( ) ) ;
661+ expect ( mocks . cancelPickElement ) . not . toHaveBeenCalled ( ) ;
662+ await act ( async ( ) => finishCapture ! ( ) ) ;
663+ expect ( mocks . addPreviewAnnotation ) . toHaveBeenCalledWith ( TEST_THREAD_REF , annotation ) ;
664+ } finally {
665+ await act ( async ( ) => root . unmount ( ) ) ;
666+ vi . unstubAllGlobals ( ) ;
667+ }
668+ } ) ;
669+
628670 it ( "does not reopen a cancelled picker after the permission update finishes" , async ( ) => {
629671 let finishUpdate : ( ( ) => void ) | undefined ;
630672 mocks . setAnnotationSendEnabled . mockImplementationOnce (
0 commit comments