Skip to content

Commit

Permalink
fix(nextjs): Use globalThis instead of global in edge runtime (#9612
Browse files Browse the repository at this point in the history
)

Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
  • Loading branch information
powerfulyang and lforst committed Nov 21, 2023
1 parent 2f17bb1 commit b8c46ea
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/nextjs/src/config/loaders/valueInjectionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function valueInjectionLoader(this: LoaderThis<LoaderOptions>, us
this.cacheable(false);

// Define some global proxy that works on server and on the browser.
let injectedCode = 'var _sentryCollisionFreeGlobalObject = typeof window === "undefined" ? global : window;\n';
let injectedCode =
'var _sentryCollisionFreeGlobalObject = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};\n';

Object.entries(values).forEach(([key, value]) => {
injectedCode += `_sentryCollisionFreeGlobalObject["${key}"] = ${JSON.stringify(value)};\n`;
Expand Down

0 comments on commit b8c46ea

Please sign in to comment.