File tree Expand file tree Collapse file tree
packages/studio/src/player Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,20 @@ describe("sceneSwapFor", () => {
7272 expect ( replaced ) . toBe ( false ) ;
7373 } ) ;
7474
75+ it ( "does not start a swap whose cancel signal was aborted before the call" , async ( ) => {
76+ const fetchSpy = vi
77+ . spyOn ( globalThis , "fetch" )
78+ . mockImplementation ( async ( ) => new Response ( "<html></html>" ) ) ;
79+ const { iframe, swap } = swappableIframe ( ) ;
80+ const cancel = new AbortController ( ) ;
81+ cancel . abort ( new Error ( "superseded by a newer edit" ) ) ;
82+ await expect ( sceneSwapFor ( iframe ) ! ( "/preview" , ( ) => true , cancel . signal ) ) . rejects . toThrow (
83+ "superseded" ,
84+ ) ;
85+ expect ( fetchSpy ) . not . toHaveBeenCalled ( ) ;
86+ expect ( swap ) . not . toHaveBeenCalled ( ) ;
87+ } ) ;
88+
7589 it ( "swaps a document that arrives in time" , async ( ) => {
7690 vi . spyOn ( globalThis , "fetch" ) . mockImplementation ( async ( ) => new Response ( "<html></html>" ) ) ;
7791 const { iframe, swap } = swappableIframe ( ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export function sceneSwapFor(
2525 const swap = win ?. __hfSwapScenes ;
2626 if ( typeof swap !== "function" ) return null ;
2727 return async ( url , isCurrent , cancel ) => {
28+ if ( cancel ?. aborted ) throw cancel . reason ;
2829 const deadline = new AbortController ( ) ;
2930 const timer = setTimeout (
3031 ( ) => deadline . abort ( new Error ( "the preview took too long to swap" ) ) ,
You can’t perform that action at this time.
0 commit comments