Skip to content

Commit

Permalink
fix(nextjs): Flush servercomponent events for edge (#9487)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Nov 8, 2023
1 parent fb0032d commit 62e562e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const dynamic = 'force-dynamic';

export const runtime = 'edge';

export default async function Page() {
throw new Error('Edge Server Component Error');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test';
import { waitForError } from '../event-proxy-server';

test('Should record exceptions for faulty edge server components', async ({ page }) => {
const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Edge Server Component Error';
});

await page.goto('/edge-server-components/error');

expect(await errorEventPromise).toBeDefined();
});
4 changes: 4 additions & 0 deletions packages/nextjs/src/common/wrapServerComponentWithSentry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addTracingExtensions,
captureException,
flush,
getCurrentHub,
runWithAsyncContext,
startTransaction,
Expand Down Expand Up @@ -81,6 +82,7 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
maybePromiseResult = originalFunction.apply(thisArg, args);
} catch (e) {
handleErrorCase(e);
void flush();
throw e;
}

Expand All @@ -94,12 +96,14 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
handleErrorCase(e);
},
);
void flush();

// It is very important that we return the original promise here, because Next.js attaches various properties
// to that promise and will throw if they are not on the returned value.
return maybePromiseResult;
} else {
transaction.finish();
void flush();
return maybePromiseResult;
}
});
Expand Down

0 comments on commit 62e562e

Please sign in to comment.