Skip to content

fix(utils): Normalize undefined to undefined instead of "[undefined]" #8017

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

Merged
merged 6 commits into from
May 3, 2023

Conversation

lforst
Copy link
Contributor

@lforst lforst commented May 2, 2023

Fixes #7933

Supersedes #8009

It's a bit weird that undefined normalizes to a string and even causes issues for users (see #7933). I suggest we change this.

@lforst lforst requested review from mydea and AbhiPrasad May 2, 2023 20:12
@lforst lforst changed the title fix(utils): Normalize undefined to undefined instead of "undefined" fix(utils): Normalize undefined to undefined instead of "[undefined]" May 2, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 2, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.01 KB (-0.05% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 65.62 KB (-0.06% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.55 KB (-0.05% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 58.08 KB (-0.06% 🔽)
@sentry/browser - Webpack (gzipped + minified) 21.16 KB (-0.04% 🔽)
@sentry/browser - Webpack (minified) 69.03 KB (-0.05% 🔽)
@sentry/react - Webpack (gzipped + minified) 21.18 KB (-0.03% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.08 KB (-0.02% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.64 KB (-0.03% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.86 KB (-0.03% 🔽)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 46.86 KB (-0.02% 🔽)
@sentry/replay - Webpack (gzipped + minified) 40.67 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 65.74 KB (-0.02% 🔽)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 58.63 KB (-0.02% 🔽)

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

I was wondering before why we even had that in the first place - IMHO usually you'll not care to see this, as it should be identical to not having this, and when JSON stringifying undefined things are normally dropped. You'll have some more tests to fix, though 😅

Comment on lines 83 to 84
value === undefined ||
value === null ||
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 (just with bundle size in mind but feel free to ignore):

Suggested change
value === undefined ||
value === null ||
value == null ||

This should be identical, just a little shorter, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I even thought about this but I stopped micro-optimizing for bundle because I assume terser will optimize this stuff away anyhow. Here I am still gonna go with your change because I don't know if it catches ths.

@@ -366,28 +366,26 @@ describe('normalize()', () => {
});

test('primitive values in objects/arrays', () => {
expect(normalize(['foo', 42, undefined, NaN])).toEqual(['foo', 42, '[undefined]', '[NaN]']);
expect(normalize(['foo', 42, NaN])).toEqual(['foo', 42, '[NaN]']);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just thinking why not keep the undefined here?

Suggested change
expect(normalize(['foo', 42, NaN])).toEqual(['foo', 42, '[NaN]']);
expect(normalize(['foo', 42, undefined, NaN])).toEqual(['foo', 42, undefined, '[NaN]']);

I would expect this to pass, or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

youre right!

@lforst lforst merged commit 02e1c1a into develop May 3, 2023
@lforst lforst deleted the lforst-undefined-normalize branch May 3, 2023 13:17
billyvg pushed a commit that referenced this pull request May 5, 2023
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.

Mismatch of type of Contexts between SDK and server
4 participants