Skip to content
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

fix(nextjs): Make SDK multiplexer more resilient #6905

Merged
merged 2 commits into from
Jan 23, 2023
Merged

Conversation

lforst
Copy link
Member

@lforst lforst commented Jan 23, 2023

https://github.com/getsentry/sentry-javascript/pull/6817/files#diff-5598248a0f2280565998f93876df482b2040cb761cc510b3bd2c4dfa5824dca8L103 seems to have broken the Next.js SDK multiplexer which is responsible for injecting the right SDK depending on whether the SDK is imported on browser/server/edge. It broke because it started stripping away the comment that told our loader to multiplex.

I suspected the comment was a little fragile from the beginning so let's make it a little bit more resilient by exporting a dummy const which is more or less guaranteed to be in the file to some extent. Maybe still not the optimal solution but better than the current one. The dummy export should not show up in types since the typing file we export doesn't actually point to the multiplexer files.

Oh, and we really need tests for middleware and edge routes. It was quite surprising that nothing caught this.

@@ -13,7 +13,7 @@ type LoaderOptions = {
* or edge-runtime code.
*/
export default function sdkMultiplexerLoader(this: LoaderThis<LoaderOptions>, userCode: string): string {
if (!userCode.includes('__SENTRY_SDK_MULTIPLEXER__')) {
if (!userCode.includes('_SENTRY_SDK_MULTIPLEXER')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: let's please leave a comment explaining why this is a exported const in the doc string

@AbhiPrasad
Copy link
Member

we really need tests for middleware and edge routes

Let's make a GH issue to track?

@lforst
Copy link
Member Author

lforst commented Jan 23, 2023

we really need tests for middleware and edge routes

Let's make a GH issue to track?

Aye! #6906

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants