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

feat(react-router): Add build-time config #15406

Merged
merged 22 commits into from
Feb 27, 2025
Merged

Conversation

chargome
Copy link
Member

@chargome chargome commented Feb 13, 2025

  • Adds a vite plugin for react router that handles:
    • Updating sourcemap settings
    • Release injection
    • Telemetry Data
  • Adds a sentryOnBuildEnd hook that handles:
    • Creating releases
    • DebugId injection
    • Uploading sourcemaps
    • Deleting sourcemaps after upload

Currently the options passed to both the plugin and the hook partly overlap which is confusing, would be nice to just have one common options object at the end. Actually I can pass these options via vite and read them in the hook

We'll need to revisit this and move DebugId injection back to the vite plugin to avoid modifying the final build. For the alpha release we'll still rely on the SentryCli.

closes #15188

@chargome chargome self-assigned this Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
4662 2 4660 324
View the top 2 failed test(s) by shortest run time
test/integration/test/client/root-loader.test.ts should throw redirect to an external path with no baggage and trace injected.
Stack Traces | 0.079s run time
root-loader.test.ts:177:1 should throw redirect to an external path with no baggage and trace injected.
test/integration/test/client/root-loader.test.ts should return redirect to an external path with no baggage and trace injected.
Stack Traces | 0.11s run time
root-loader.test.ts:165:1 should return redirect to an external path with no baggage and trace injected.

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@chargome chargome force-pushed the cg/rr-build-time-config branch from 152b618 to dca9d06 Compare February 17, 2025 09:08
@chargome chargome changed the title feat(react-router): Add vite plugin feat(react-router): Add build-time config Feb 21, 2025
@chargome chargome marked this pull request as ready for review February 24, 2025 14:13
@chargome chargome requested review from s1gr1d, a team, stephanie-anderson and Lms24 and removed request for a team and stephanie-anderson February 24, 2025 14:13
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 approach generally looks good to me (as we already discussed offline). I think it's good to try to get debugId injection into the plugin but it's totally fine to go with this solution for the alpha. Likewise, I had some comments for things to address after the initial alpha but IMHO they don't block a first alpha release.

export default defineConfig(config => {
return {
plugins: [reactRouter(), sentryReactRouter(sentryConfig, config)],
sentryConfig,
Copy link
Member

Choose a reason for hiding this comment

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

l: just to confirm does this not throw a type error? or is defineConfig lenient enough to allow adding arbitrary keys to the config object?

Copy link
Member

@Lms24 Lms24 Feb 26, 2025

Choose a reason for hiding this comment

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

Also something to explore in the future: Maybe we can add a plugin in sentryReactRouter that adds the sentryConfig in the config hook to the vite config, so that users don't have to do it explicitly. Not sure if you already tried this, or which instance of the vite config is passed into buildEnd but maybe it's worth a shot. we could even try to write it onto the global object to pass it over 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't throw a type error, but you are right the best solution for this would be to define this in a plugin that we add! Will do that in a follow up task

let updatedFilesToDeleteAfterUpload = sourceMapsUploadOptions?.filesToDeleteAfterUpload;
// set a default value no option was set
if (typeof sourceMapsUploadOptions?.filesToDeleteAfterUpload === 'undefined') {
updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];
Copy link
Member

Choose a reason for hiding this comment

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

m/something to follow up on: We only want to delete source maps by default if it was us who turned on source map generation in the first place. This was the reason why I had to pass the promise for filesToDeleteAfterUpload in SvelteKit, because I only knew that once makeEnableSourceMapsPlugin's config hook was invoked. But since we have the vite config here, and we don't rely on the original file deletion plugin, maybe we can solve this simpler 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah my issue was that I only get the final vite config here and not the initial one, BUT I guess we can maybe just write that into the config as well with a custom plugin (like the sentryConfig from your comment above)


export default {
ssr: true,
buildEnd: sentryOnBuildEnd,
Copy link
Member

@Lms24 Lms24 Feb 26, 2025

Choose a reason for hiding this comment

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

l/Q: is there some kind of sequence() helper or so in case people have more than one buildEnd callback?

Copy link
Member Author

Choose a reason for hiding this comment

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

in this case they could just

buildEnd: ({ viteConfig, reactRouterConfig, buildManifest }) => {
    // do their stuff
    sentryOnBuildEnd({ viteConfig, reactRouterConfig, buildManifest });
  },

@chargome chargome merged commit 9a55e17 into develop Feb 27, 2025
150 checks passed
@chargome chargome deleted the cg/rr-build-time-config branch February 27, 2025 09:39
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.

[RR7] Add build time configuration
3 participants