-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref(nextjs): Use generic loader to inject global values #6484
Conversation
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great refactor, much easier to understand. Only had a question about the isomorphic values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea!
Probably out of scope for this PR, but as the number of values we're shoving into the global namespace increases, I'm wondering if we should maybe think about putting them inside of __SENTRY__
. WDYT?
const { values } = 'getOptions' in this ? this.getOptions() : this.query; | ||
|
||
// Define some global proxy that works on server and on the browser. | ||
let injectedCode = 'var _sentryCollisionFreeGlobalObject = typeof window === "undefined" ? global : window;\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M: Do we need to worry about web workers/self
here, do you think? Is there a reason not to just use GLOBAL_OBJ
from @sentry/utils
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to worry about web workers here. The loader is only applied to sentry.server.config.js
and sentry.client.config.js
and I think we are safe to assume that sentry.client.config.js
will not be injected into any web worker contexts. Unless I am missing something.
Considering the above I would just keep it as-is to keep the logic simple.
Had a very similar thought. We probably should at some point - right now it would bloat the logic of the loader a lot. Let's see how many values we'll be injecting first. |
Refactor to add a webpack loader to the Next.js SDK to inject global variables into both the browser and the server-side SDK.
This change is needed for #5571 where we need to put a string on the global scope in the build step to read from during runtime. We have the prefix loader that is able to inject pretty much any code in the SDK - that would have also been an option to use but it seemed a bit overkill for this simple use-case.
This loader will also potentially become useful in the future for planned heartbeat/pulse checks during initialization to check if the SDK has been set up correctly.