Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ui/desktop/src/components/recipes/CreateEditRecipeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export default function CreateEditRecipeModal({
// Generate deeplink whenever recipe configuration changes
useEffect(() => {
let isCancelled = false;
const abortController = new AbortController();

const generateLink = async () => {
if (
Expand All @@ -353,11 +354,14 @@ export default function CreateEditRecipeModal({
setIsGeneratingDeeplink(true);
try {
const currentRecipe = getCurrentRecipe();
const link = await generateDeepLink(currentRecipe);
const link = await generateDeepLink(currentRecipe, abortController.signal);
if (!isCancelled) {
setDeeplink(link);
}
} catch (error) {
if (abortController.signal.aborted) {
return;
}
console.error('Failed to generate deeplink:', error);
if (!isCancelled) {
setDeeplink('Error generating deeplink');
Expand All @@ -369,10 +373,12 @@ export default function CreateEditRecipeModal({
}
};

generateLink();
const timeoutId = window.setTimeout(generateLink, 500);

return () => {
isCancelled = true;
abortController.abort();
window.clearTimeout(timeoutId);
};
}, [
title,
Expand Down
9 changes: 6 additions & 3 deletions ui/desktop/src/recipe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export type Recipe = import('../api').Recipe & {
isScheduledExecution?: boolean;
};

export async function encodeRecipe(recipe: Recipe): Promise<string> {
type ApiSignal = Parameters<typeof apiEncodeRecipe>[0]['signal'];

export async function encodeRecipe(recipe: Recipe, signal?: ApiSignal): Promise<string> {
try {
const response = await apiEncodeRecipe({
body: { recipe },
signal,
});

if (!response.data) {
Expand Down Expand Up @@ -71,8 +74,8 @@ export async function scanRecipe(recipe: Recipe): Promise<{ has_security_warning
}
}

export async function generateDeepLink(recipe: Recipe): Promise<string> {
const encoded = await encodeRecipe(recipe);
export async function generateDeepLink(recipe: Recipe, signal?: ApiSignal): Promise<string> {
const encoded = await encodeRecipe(recipe, signal);
return `goose://recipe?config=${encoded}`;
}

Expand Down
Loading