Use Object.create(null) over {} to avoid prototype issues#4634
Use Object.create(null) over {} to avoid prototype issues#4634
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
| ); | ||
| } | ||
| return coercedValues; | ||
| return { ...coercedValues }; |
There was a problem hiding this comment.
is this strictly necessary?
There was a problem hiding this comment.
Without it, it's a breaking change (assuming this is reachable from user code) since you'd be returning a null prototype object rather than a prototypeful object. Users who did console.log(`Blah blah ${obj} blah blah`) would have their code change from logging Blah blah [object Object] blah blah to throwing an error.
> const a = {}
undefined
> const b = Object.create(null)
undefined
> String(a)
'[object Object]'
> String(b)
Uncaught TypeError: Cannot convert object to primitive value
at String (<anonymous>)
The reason I didn't merge this myself is because ideally we'd just switch to null prototype objects and get rid of the problem entirely. But I didn't want to introduce a breaking change, hence including this careful back-compat.
Personally I vote to remove this.
| } | ||
|
|
||
| return coercedValue; | ||
| return { ...coercedValue }; |
Forward-port of #4631