File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -339,6 +339,7 @@ export default function CreateEditRecipeModal({
339339 // Generate deeplink whenever recipe configuration changes
340340 useEffect ( ( ) => {
341341 let isCancelled = false ;
342+ const abortController = new AbortController ( ) ;
342343
343344 const generateLink = async ( ) => {
344345 if (
@@ -353,11 +354,14 @@ export default function CreateEditRecipeModal({
353354 setIsGeneratingDeeplink ( true ) ;
354355 try {
355356 const currentRecipe = getCurrentRecipe ( ) ;
356- const link = await generateDeepLink ( currentRecipe ) ;
357+ const link = await generateDeepLink ( currentRecipe , abortController . signal ) ;
357358 if ( ! isCancelled ) {
358359 setDeeplink ( link ) ;
359360 }
360361 } catch ( error ) {
362+ if ( abortController . signal . aborted ) {
363+ return ;
364+ }
361365 console . error ( 'Failed to generate deeplink:' , error ) ;
362366 if ( ! isCancelled ) {
363367 setDeeplink ( 'Error generating deeplink' ) ;
@@ -369,10 +373,12 @@ export default function CreateEditRecipeModal({
369373 }
370374 } ;
371375
372- generateLink ( ) ;
376+ const timeoutId = window . setTimeout ( generateLink , 500 ) ;
373377
374378 return ( ) => {
375379 isCancelled = true ;
380+ abortController . abort ( ) ;
381+ window . clearTimeout ( timeoutId ) ;
376382 } ;
377383 } , [
378384 title ,
Original file line number Diff line number Diff line change @@ -15,10 +15,13 @@ export type Recipe = import('../api').Recipe & {
1515 isScheduledExecution ?: boolean ;
1616} ;
1717
18- export async function encodeRecipe ( recipe : Recipe ) : Promise < string > {
18+ type ApiSignal = Parameters < typeof apiEncodeRecipe > [ 0 ] [ 'signal' ] ;
19+
20+ export async function encodeRecipe ( recipe : Recipe , signal ?: ApiSignal ) : Promise < string > {
1921 try {
2022 const response = await apiEncodeRecipe ( {
2123 body : { recipe } ,
24+ signal,
2225 } ) ;
2326
2427 if ( ! response . data ) {
@@ -71,8 +74,8 @@ export async function scanRecipe(recipe: Recipe): Promise<{ has_security_warning
7174 }
7275}
7376
74- export async function generateDeepLink ( recipe : Recipe ) : Promise < string > {
75- const encoded = await encodeRecipe ( recipe ) ;
77+ export async function generateDeepLink ( recipe : Recipe , signal ?: ApiSignal ) : Promise < string > {
78+ const encoded = await encodeRecipe ( recipe , signal ) ;
7679 return `goose://recipe?config=${ encoded } ` ;
7780}
7881
You can’t perform that action at this time.
0 commit comments