From 6232441b636d6128c49809e3c563839344a841f4 Mon Sep 17 00:00:00 2001 From: Adrian Lam Date: Wed, 12 Nov 2025 21:43:03 -0800 Subject: [PATCH 1/3] refactor(builder): add suppressUndefinedRejections --- packages/builders/src/base-builder.ts | 7 ++++++- packages/sveltekit/src/builder.ts | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/builders/src/base-builder.ts b/packages/builders/src/base-builder.ts index 0d6752a20d..4c309e2449 100644 --- a/packages/builders/src/base-builder.ts +++ b/packages/builders/src/base-builder.ts @@ -671,13 +671,18 @@ export const POST = workflowEntrypoint(workflowCode);`; * Creates a webhook handler bundle for resuming workflows via HTTP callbacks. * * @param bundle - If true, bundles dependencies (needed for Build Output API) + * @param suppressUndefinedRejections - If true, suppresses undefined rejections. + * This is a workaround to avoid crashing in local + * dev when context isn't set for waitUntil() */ protected async createWebhookBundle({ outfile, bundle = false, + suppressUndefinedRejections = false, }: { outfile: string; bundle?: boolean; + suppressUndefinedRejections?: boolean; }): Promise { console.log('Creating webhook route'); await mkdir(dirname(outfile), { recursive: true }); @@ -725,7 +730,7 @@ export const OPTIONS = handler;`; const webhookBundleStart = Date.now(); const result = await esbuild.build({ banner: { - js: '// biome-ignore-all lint: generated file\n/* eslint-disable */\n', + js: `// biome-ignore-all lint: generated file\n/* eslint-disable */\n${suppressUndefinedRejections ? 'process.on("unhandledRejection", (reason) => { if (reason !== undefined) console.error("Unhandled rejection detected", reason); });' : ''}`, }, stdin: { contents: routeContent, diff --git a/packages/sveltekit/src/builder.ts b/packages/sveltekit/src/builder.ts index affc7b70eb..07d3d56045 100644 --- a/packages/sveltekit/src/builder.ts +++ b/packages/sveltekit/src/builder.ts @@ -155,15 +155,12 @@ export const POST = async ({request}) => { await this.createWebhookBundle({ outfile: webhookRouteFile, bundle: false, // SvelteKit will handle bundling + suppressUndefinedRejections: true, }); // Post-process the generated file to wrap with SvelteKit request converter let webhookRouteContent = await readFile(webhookRouteFile, 'utf-8'); - // NOTE: This is a workaround to avoid crashing in local dev when context isn't set for waitUntil() - webhookRouteContent = `process.on('unhandledRejection', (reason) => { if (reason !== undefined) console.error('Unhandled rejection detected', reason); }); -${webhookRouteContent}`; - // Update handler signature to accept token as parameter webhookRouteContent = webhookRouteContent.replace( /async function handler\(request\) \{[\s\S]*?const token = decodeURIComponent\(pathParts\[pathParts\.length - 1\]\);/, From 9fb1133639cec2ec553ac6de901cf4b6b6e2708b Mon Sep 17 00:00:00 2001 From: Adrian Lam Date: Wed, 12 Nov 2025 22:04:19 -0800 Subject: [PATCH 2/3] fix where undefined rejection line should be --- packages/builders/src/base-builder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builders/src/base-builder.ts b/packages/builders/src/base-builder.ts index 4c309e2449..502b655d55 100644 --- a/packages/builders/src/base-builder.ts +++ b/packages/builders/src/base-builder.ts @@ -689,7 +689,7 @@ export const POST = workflowEntrypoint(workflowCode);`; // Create a static route that calls resumeWebhook // This route works for both Next.js and Vercel Build Output API - const routeContent = `import { resumeWebhook } from 'workflow/api'; + const routeContent = `${suppressUndefinedRejections ? 'process.on("unhandledRejection", (reason) => { if (reason !== undefined) console.error("Unhandled rejection detected", reason); });' : ''}import { resumeWebhook } from 'workflow/api'; async function handler(request) { const url = new URL(request.url); @@ -730,7 +730,7 @@ export const OPTIONS = handler;`; const webhookBundleStart = Date.now(); const result = await esbuild.build({ banner: { - js: `// biome-ignore-all lint: generated file\n/* eslint-disable */\n${suppressUndefinedRejections ? 'process.on("unhandledRejection", (reason) => { if (reason !== undefined) console.error("Unhandled rejection detected", reason); });' : ''}`, + js: `// biome-ignore-all lint: generated file\n/* eslint-disable */`, }, stdin: { contents: routeContent, From c18cc2bb650f914284297eda527ce8cb8927f34e Mon Sep 17 00:00:00 2001 From: Adrian Lam Date: Wed, 12 Nov 2025 22:16:50 -0800 Subject: [PATCH 3/3] refactor --- packages/builders/src/base-builder.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/builders/src/base-builder.ts b/packages/builders/src/base-builder.ts index 502b655d55..9715d5e20f 100644 --- a/packages/builders/src/base-builder.ts +++ b/packages/builders/src/base-builder.ts @@ -689,7 +689,8 @@ export const POST = workflowEntrypoint(workflowCode);`; // Create a static route that calls resumeWebhook // This route works for both Next.js and Vercel Build Output API - const routeContent = `${suppressUndefinedRejections ? 'process.on("unhandledRejection", (reason) => { if (reason !== undefined) console.error("Unhandled rejection detected", reason); });' : ''}import { resumeWebhook } from 'workflow/api'; + const routeContent = `${suppressUndefinedRejections ? 'process.on("unhandledRejection", (reason) => { if (reason !== undefined) console.error("Unhandled rejection detected", reason); });\n' : ''} +import { resumeWebhook } from 'workflow/api'; async function handler(request) { const url = new URL(request.url);