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(nuxt): Base decision on source maps upload only on Nuxt source map settings #15859

Merged
merged 9 commits into from
Apr 3, 2025

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Mar 27, 2025

There is a total of 6 settings in Nuxt where you can disable/enable your source maps. This is not only difficult to understand when writing and maintaining the logic for this. It may also be hard to debug stuff for users.

image

There is this discussion around Nuxt source maps: #15028
And this issue: #15160

A problem with the current setup was not only the difficulty to understand all of this but also it sometimes just overwrote stuff you didn't want it to. Like in the default case of Nuxt, sourcemap.server is true, but as nitro.rollupConfig.output.sourcemap is always undefined, Sentry would overwrite this setting to 'hidden', even though the source maps were enabled already.


The only two relevant options in Nuxt are the root-level sourcemap options. Those settings will propagate to nitro, vite and rollup.

As we overwrite the source maps setting if the setting is undefined, only the basic Nuxt source map settings (linked above) are taken into account for that from now on.

@s1gr1d s1gr1d self-assigned this Mar 27, 2025
@s1gr1d s1gr1d requested a review from Copilot March 27, 2025 15:30
Copilot

This comment was marked as outdated.

@s1gr1d s1gr1d requested review from Copilot, lforst and Lms24 March 28, 2025 12:47
@s1gr1d s1gr1d marked this pull request as ready for review March 28, 2025 12:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how source map settings are handled in Nuxt so that decision-making is solely based on Nuxt’s root-level source map options, reducing complexity and preventing unintended overwrites.

  • Unified source map configuration for Vite and Nitro using Nuxt settings.
  • Refactored logging and validation functions for clearer, consolidated behavior.
  • Updated tests to verify fallback logic for deleting files after upload.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/nuxt/test/vite/sourceMaps.test.ts Updated tests to reflect new plugin options and fallback behavior for file deletion.
packages/nuxt/src/vite/sourceMaps.ts Refactored source map settings handling to rely on Nuxt config, improved logging, and added validation helpers.
Comments suppressed due to low confidence (2)

packages/nuxt/src/vite/sourceMaps.ts:144

  • [nitpick] Consider renaming 'fallbackFilesToDelete' to 'defaultFilesToDeleteAfterUpload' to better reflect its purpose as the default deletion pattern for generated source maps.
const fallbackFilesToDelete = [

packages/nuxt/test/vite/sourceMaps.test.ts:155

  • [nitpick] Consider adding additional test cases that validate behavior when both client and server fallback options are false, ensuring that no deletion patterns are set in those scenarios.
it('sets filesToDeleteAfterUpload correctly based on fallback options', () => {

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.

Thanks for the great PR explanation 🙏 and for digging through this mess of source maps options 😅

I think the approach to only change nuxt config source map settings and warn on divergences in lower level settings sounds very reasonable. My comments are mainly focused around avoiding user confusions with log messages and tests.

@@ -275,24 +370,24 @@ function logKeepSourceMapSetting(
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.log(
`[Sentry] We discovered \`${settingKey}\` is set to \`${settingValue}\`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.`,
`[Sentry] We discovered \`${settingKey}\` is set to \`${settingValue}\`. This will un-minify the code snippet on the Sentry Issue page. Be aware that there might be other source map settings in your config which could overwrite this setting.`,
Copy link
Member

Choose a reason for hiding this comment

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

l: should we keep the "be aware" sentence here? as far as I understand, we'd emit an explicit warning anyway via validateDifferentSourceMapSettings, right?

The reason why I'm thinking about this is that this should be a "success message", right? I just want to convey this and not risk users thinking they did something wrong or mistake the message with a warning. Especially with "hidden" I could see users being confused.

What about something like this?

Suggested change
`[Sentry] We discovered \`${settingKey}\` is set to \`${settingValue}\`. This will un-minify the code snippet on the Sentry Issue page. Be aware that there might be other source map settings in your config which could overwrite this setting.`,
`[Sentry] \`${settingKey}\` is already set to \`${settingValue}\`. This will correctly un-minify the code snippet on the Sentry Issue page.`

Which brings me to an alternative question/idea: Do we even need this message at all? In case of users already having source maps enabled, there's nothing for us to do anyway, right? Not saying it has to go, just food for thought :)

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'll change this to your suggestion but will keep it to show it when debug is enabled :)

@@ -148,146 +151,187 @@ describe('getPluginOptions', () => {
}),
);
});

it('sets filesToDeleteAfterUpload correctly based on fallback options', () => {
Copy link
Member

Choose a reason for hiding this comment

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

super-l: is there a reason to test multiple scenarios in one test? no strong feelings but I personally prefer sticking to one scenario per test (could be it.each or separate tests) because it makes it easier to see what specifically fails. But feel free to disregard and stick with this.


beforeEach(() => {
cases.forEach(({ clientSourcemap, expectedSourcemap, expectedReturn }) => {
Copy link
Member

Choose a reason for hiding this comment

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

l: We can rewrite this as well as the cases below to it.each instead of iterating over the loop. My main concern is seeing what exactly failed which is a bit difficult in the loop (especially when just checking CI logs).

@s1gr1d s1gr1d merged commit 6501d52 into develop Apr 3, 2025
151 of 152 checks passed
@s1gr1d s1gr1d deleted the sig/source-maps-nuxt branch April 3, 2025 08:42
onurtemizkan pushed a commit that referenced this pull request Apr 3, 2025
…ap settings (#15859)

There is a total of 6 settings in Nuxt where you can disable/enable your
source maps. This is not only difficult to understand when writing and
maintaining the logic for this. It may also be hard to debug stuff for
users.


![image](https://github.com/user-attachments/assets/73ff315e-2000-4408-ba62-39bd10083378)

There is this discussion around Nuxt source maps:
#15028
And this issue:
#15160

A problem with the current setup was not only the difficulty to
understand all of this but also it sometimes just overwrote stuff you
didn't want it to. Like in the default case of Nuxt, `sourcemap.server`
is `true`, but as `nitro.rollupConfig.output.sourcemap` is always
undefined, Sentry would overwrite this setting to `'hidden'`, even
though the source maps were enabled already.

---

The only two relevant options in Nuxt are the [root-level sourcemap
options](https://nuxt.com/docs/guide/going-further/debugging#sourcemaps).
Those settings will propagate to nitro, vite and rollup.

As we overwrite the source maps setting if the setting is undefined,
only the basic Nuxt source map settings (linked above) are taken into
account for that from now on.
s1gr1d added a commit that referenced this pull request Apr 4, 2025
Improving tests for
#15859

- added `it.each` instead of looping with `foreach`
- added tests for console output
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