Skip to content

Commit 62e562e

Browse files
authored
fix(nextjs): Flush servercomponent events for edge (#9487)
1 parent fb0032d commit 62e562e

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const dynamic = 'force-dynamic';
2+
3+
export const runtime = 'edge';
4+
5+
export default async function Page() {
6+
throw new Error('Edge Server Component Error');
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test, expect } from '@playwright/test';
2+
import { waitForError } from '../event-proxy-server';
3+
4+
test('Should record exceptions for faulty edge server components', async ({ page }) => {
5+
const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => {
6+
return errorEvent?.exception?.values?.[0]?.value === 'Edge Server Component Error';
7+
});
8+
9+
await page.goto('/edge-server-components/error');
10+
11+
expect(await errorEventPromise).toBeDefined();
12+
});

packages/nextjs/src/common/wrapServerComponentWithSentry.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
addTracingExtensions,
33
captureException,
4+
flush,
45
getCurrentHub,
56
runWithAsyncContext,
67
startTransaction,
@@ -81,6 +82,7 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
8182
maybePromiseResult = originalFunction.apply(thisArg, args);
8283
} catch (e) {
8384
handleErrorCase(e);
85+
void flush();
8486
throw e;
8587
}
8688

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

98101
// It is very important that we return the original promise here, because Next.js attaches various properties
99102
// to that promise and will throw if they are not on the returned value.
100103
return maybePromiseResult;
101104
} else {
102105
transaction.finish();
106+
void flush();
103107
return maybePromiseResult;
104108
}
105109
});

0 commit comments

Comments
 (0)