-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
undefined
to undefined
instead of "undefined"
undefined
to undefined
instead of "[undefined]"
size-limit report 📦
|
There was a problem hiding this 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 😅
packages/utils/src/normalize.ts
Outdated
value === undefined || | ||
value === null || |
There was a problem hiding this comment.
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):
value === undefined || | |
value === null || | |
value == null || |
This should be identical, just a little shorter, right?
There was a problem hiding this comment.
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]']); |
There was a problem hiding this comment.
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?
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
youre right!
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.