Skip to content

Commit

Permalink
feat(nextjs): Check for Vercel Edge Function GA (#6565)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Dec 20, 2022
1 parent 604cbf1 commit 6e27ce9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/nextjs/src/config/templates/apiProxyLoaderTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ export const config = {
},
};

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

export default userProvidedHandler
? isEdgeRuntime
? userProvidedHandler
: Sentry.withSentryAPI(userProvidedHandler, '__ROUTE__')
: undefined;
let exportedHandler;

if (typeof EdgeRuntime === 'string') {
exportedHandler = userProvidedHandler;
} else {
exportedHandler = userProvidedHandler ? Sentry.withSentryAPI(userProvidedHandler, '__ROUTE__') : undefined;
}

export default exportedHandler;

// Re-export anything exported by the page module we're wrapping. When processing this code, Rollup is smart enough to
// not include anything whose name matchs something we've explicitly exported above.
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/src/index.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ declare const __SENTRY_TRACING__: boolean;
// This is a variable that Next.js will string replace during build with a string if run in an edge runtime from Next.js
// v12.2.1-canary.3 onwards:
// https://github.com/vercel/next.js/blob/166e5fb9b92f64c4b5d1f6560a05e2b9778c16fb/packages/next/build/webpack-config.ts#L206
// https://edge-runtime.vercel.sh/features/available-apis#addressing-the-runtime
declare const EdgeRuntime: string | undefined;

const globalWithInjectedValues = global as typeof global & {
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const domain = domainModule as typeof domainModule & { active: (domainModule.Dom
// This is a variable that Next.js will string replace during build with a string if run in an edge runtime from Next.js
// v12.2.1-canary.3 onwards:
// https://github.com/vercel/next.js/blob/166e5fb9b92f64c4b5d1f6560a05e2b9778c16fb/packages/next/build/webpack-config.ts#L206
// https://edge-runtime.vercel.sh/features/available-apis#addressing-the-runtime
declare const EdgeRuntime: string | undefined;

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

0 comments on commit 6e27ce9

Please # to comment.