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

ref: Optimize build configs and builds #480

Merged
merged 3 commits into from
Aug 9, 2024
Merged

ref: Optimize build configs and builds #480

merged 3 commits into from
Aug 9, 2024

Conversation

BYK
Copy link
Member

@BYK BYK commented Aug 7, 2024

This change mainly removes the enforcement of process.env.NODE_ENV === 'development' for Spotlight which in turn also enables significant bundle size savings as we include the React library which does optimizations based on this value.

Without the patch:

File Size Gzipped Map
dist/sentry-spotlight.js 0.65 kB 0.39 kB 0.10 kB
dist/main-f821b601.js 163.24 kB 38.35 kB 267.29 kB
dist/index-122c6ab6.js 1,472.54 kB 455.16 kB 3,871.30 kB
dist/sentry-spotlight.iife.js 1,206.02 kB 437.51 kB 4,010.64 kB

With the patch:

File Size Gzipped Map
dist/sentry-spotlight.js 0.65 kB 0.39 kB 0.10 kB
dist/main-02efbde8.js 163.24 kB 38.35 kB 267.29 kB
dist/index-8591b57c.js 1,181.10 kB 384.51 kB 2,516.24 kB
dist/sentry-spotlight.iife.js 1,016.89 kB 380.25 kB 2,679.17 kB

Copy link

vercel bot commented Aug 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
spotlightjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 7, 2024 3:29pm

@BYK BYK requested a review from Lms24 August 7, 2024 15:18
@BYK BYK marked this pull request as ready for review August 7, 2024 15:18
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

The build changes look fine to me although I remember we had some issues with process for some reason ending up in client code and of course being undefined. I'm curious if the changes here solve this or if we'd regress. But to be honest, I didn't make these changes back then so can't tell you specifics unfortunately :/

Also had another question

integrations: [customIntegration()],
});
}
Spotlight.init({
Copy link
Member

Choose a reason for hiding this comment

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

I'm aware that this is just an e2e test app but is this how we want users to use Spotlight in the future?
I'm probably missing something but if this guard is removed, spotlight overlay code ends up in the production build of the NextJS application. Currently we document spotlight setup with this guard in place so that users don't accidentally include it in their prod bundles.

The reason is that bundlers are smart enough to remove code within the process.env.NODE_ENV check if the condition evaluates to false at build time.

@@ -12,5 +12,5 @@ Sentry.init({

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
spotlight: process.env.NODE_ENV === 'development',
spotlight: true,
Copy link
Member

Choose a reason for hiding this comment

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

same question generally here: If this is always true, the integration will also try to send events to the side car in production. Is this what we want?

Copy link
Member Author

Choose a reason for hiding this comment

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

I never considered these test codes as representative examples for usage (as we also set debug: true on some places). I removed the conditionals mostly to avoid any confusing test issues in case we mess with NODE_ENV value for some reason (builds, installing dependencies etc).

For representative code examples, docs should be the main source of truth and yes ideally, Spotlight should not be included in production code but if one wants to do it, we do have a warning somewhere in the code :)

Copy link
Member

Choose a reason for hiding this comment

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

Ok I see, that makes sense! Fwiw, at least when I worked on Spotlight the e2e tests were quite messy and probably didn't always reflect what we instruct users to do. I think generally, it's good to stay close to how we instruct the setup but honestly, no strong feelings for this one here.

Just wanted to make sure we're aware of the bundling/tree-shaking checks around prod vs dev.

@BYK
Copy link
Member Author

BYK commented Aug 7, 2024

The build changes look fine to me although I remember we had some issues with process for some reason ending up in client code and of course being undefined. I'm curious if the changes here solve this or if we'd regress. But to be honest, I didn't make these changes back then so can't tell you specifics unfortunately :/

For this, I rely on e2e tests as it should be caught there. That said I'll do another manual pass before merging to make sure this doesn't cause any issues. It may as well be solved with newer versions of vite too.

@BYK BYK requested a review from Lms24 August 8, 2024 13:30
@BYK BYK merged commit e5b84d2 into main Aug 9, 2024
13 checks passed
@BYK BYK deleted the byk/ref/optimize-builds branch August 9, 2024 10:35
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