8000 feat(nextjs): Check for Vercel Edge Function GA (#6565) · danieliu/sentry-javascript@6e27ce9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e27ce9

Browse files
authored
feat(nextjs): Check for Vercel Edge Function GA (getsentry#6565)
1 parent 604cbf1 commit 6e27ce9

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

packages/nextjs/src/config/templates/apiProxyLoaderTemplate.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,21 @@ export const config = {
5353
},
5454
};
5555

56-
const isEdgeRuntime = origConfig.runtime === 'experimental-edge';
56+
// This is a variable that Next.js will string replace during build with a string if run in an edge runtime from Next.js
57+
// v12.2.1-canary.3 onwards:
58+
// https://github.com/vercel/next.js/blob/166e5fb9b92f64c4b5d1f6560a05e2b9778c16fb/packages/next/build/webpack-config.ts#L206
59+
// https://edge-runtime.vercel.sh/features/available-apis#addressing-the-runtime
60+
declare const EdgeRuntime: string | undefined;
5761

58-
export default userProvidedHandler
59-
? isEdgeRuntime
60-
? userProvidedHandler
61-
: Sentry.withSentryAPI(userProvidedHandler, '__ROUTE__')
62-
: undefined;
62+
let exportedHandler;
63+
64+
if (typeof EdgeRuntime === 'string') {
65+
exportedHandler = userProvidedHandler;
66+
} else {
67+
exportedHandler = userProvidedHandler ? Sentry.withSentryAPI(userProvidedHandler, '__ROUTE__') : undefined;
68+
}
69+
70+
export default exportedHandler;
6371

6472
// Re-export anything exported by the page module we're wrapping. When processing this code, Rollup is smart enough to
6573
// not include anything whose name matchs something we've explicitly exported above.

packages/nextjs/src/index.client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare const __SENTRY_TRACING__: boolean;
3434
// This is a variable that Next.js will string replace during build with a string if run in an edge runtime from Next.js
3535
// v12.2.1-canary.3 onwards:
3636
// https://github.com/vercel/next.js/blob/166e5fb9b92f64c4b5d1f6560a05e2b9778c16fb/packages/next/build/webpack-config.ts#L206
37+
// https://edge-runtime.vercel.sh/features/available-apis#addressing-the-runtime
3738
declare const EdgeRuntime: string | undefined;
3839

3940
const globalWithInjectedValues = global as typeof global & {

packages/nextjs/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const domain = domainModule as typeof domainModule & { active: (domainModule.Dom
3333
// This is a variable that Next.js will string replace during build with a string if run in an edge runtime from Next.js
3434
// v12.2.1-canary.3 onwards:
3535
// https://github.com/vercel/next.js/blob/166e5fb9b92f64c4b5d1f6560a05e2b9778c16fb/packages/next/build/webpack-config.ts#L206
36+
// https://edge-runtime.vercel.sh/features/available-apis#addressing-the-runtime
3637
declare const EdgeRuntime: string | undefined;
3738

3839
// Exporting this constant means we can compute it without the linter complaining, even if we stop directly using it in

0 commit comments

Comments
 (0)
0