@@ -152,6 +152,9 @@ function makeContext(onClose?: (context: BrowserContext) => void) {
152152 goto : vi . fn ( async ( next : string ) => {
153153 url = next ;
154154 events . emit ( "load" ) ;
155+ const pending = initialNavigation ;
156+ initialNavigation = null ;
157+ await pending ?.( ) ;
155158 } ) ,
156159 goBack : vi . fn ( async ( ) => { } ) ,
157160 goForward : vi . fn ( async ( ) => { } ) ,
@@ -206,6 +209,7 @@ let pageCopy = "";
206209let keyCopy = "" ;
207210let focusedFrame : ReturnType < typeof makeFrame > | null = null ;
208211let contextFailure : Error | null = null ;
212+ let initialNavigation : ( ( ) => Promise < void > ) | null = null ;
209213let desktopRendersNext = false ;
210214const desktopDetaches = new NodeEvents . EventEmitter ( ) ;
211215const desktopTabs = new Set < string > ( ) ;
@@ -316,6 +320,7 @@ beforeEach(() => {
316320 contextRequests . length = 0 ;
317321 contextGate = null ;
318322 contextFailure = null ;
323+ initialNavigation = null ;
319324 pageCopy = "" ;
320325 keyCopy = "" ;
321326 focusedFrame = null ;
@@ -660,6 +665,41 @@ it.live.each([
660665 ) . pipe ( Effect . provide ( layer ) ) ,
661666) ;
662667
668+ it . live ( "a user-opened tab allows a corrected URL before its initial navigation commits" , ( ) =>
669+ Effect . scoped (
670+ Effect . gen ( function * ( ) {
671+ const { browser } = yield * ready ;
672+ const manager = yield * Manager . PreviewManager ;
673+ yield * Effect . yieldNow ;
674+ const started = Promise . withResolvers < void > ( ) ;
675+ const committed = Promise . withResolvers < void > ( ) ;
676+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => committed . resolve ( ) ) ) ;
677+ initialNavigation = ( ) => {
678+ started . resolve ( ) ;
679+ return committed . promise ;
680+ } ;
681+ const opened = yield * manager . open ( {
682+ threadId : scope . thread . threadId ,
683+ url : "http://localhost:5173/stalled" ,
684+ runtime : "server" ,
685+ } ) ;
686+ yield * Effect . promise ( ( ) => started . promise ) ;
687+ const viewer = yield * browser . attachViewer ( viewerInput ( opened . tabId , true ) ) ;
688+ const correction = yield * viewer
689+ . input ( { type : "navigate" , url : "http://localhost:5173/fixed" } )
690+ . pipe ( Effect . forkScoped ) ;
691+ yield * Effect . promise ( ( ) => new Promise < void > ( ( resolve ) => setImmediate ( resolve ) ) ) ;
692+ const lastNavigationBeforeCommit = contexts [ 1 ] ! . page . goto . mock . calls . at ( - 1 ) ;
693+ committed . resolve ( ) ;
694+ yield * Fiber . join ( correction ) ;
695+ expect ( lastNavigationBeforeCommit ) . toEqual ( [
696+ "http://localhost:5173/fixed" ,
697+ expect . objectContaining ( { waitUntil : "commit" } ) ,
698+ ] ) ;
699+ } ) ,
700+ ) . pipe ( Effect . provide ( layer ) ) ,
701+ ) ;
702+
663703it . live ( "an expired queued click never reaches the page" , ( ) =>
664704 Effect . scoped (
665705 Effect . gen ( function * ( ) {
0 commit comments