-
Notifications
You must be signed in to change notification settings - Fork 174
replace delete with assigning to undefined #1007
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
base: main
Are you sure you want to change the base?
replace delete with assigning to undefined #1007
Conversation
🦋 Changeset detectedLatest commit: e86d4c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
// Next.js doesn't parse body if the property exists | ||
// https://github.com/dougmoscrop/serverless-http/issues/227 | ||
delete req.body; | ||
req.body = undefined; |
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.
The comment above explicitely says "the property exists"
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.
Might be worth an upstream pr to next.js tho I suspect it's been tried before.
The key challenge with using delete
here is that it immediately puts req
into a slower / non-optimized mode for all property accesses. Whether or not that moves the needle or not in performance depends on usage pattern. In this particular case, let's leave this as delete req.body
and see if we can try to fix upstream.
but as a general rule, we should be avoiding delete
like the plague.
continue; | ||
} | ||
const keyLower = key.toLowerCase(); | ||
if (keyLower === "set-cookie") { |
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.
is that a change in behavior?
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.
Let's take more time to evaluate the changes in this PR (see my inline comments).
It should not have a huge impact anyway
// We need to remove the set-cookie header from the parsed headers because | ||
// it does not handle multiple set-cookie headers properly | ||
delete parsedHeaders[SET_COOKIE_HEADER]; | ||
|
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 see this is removed but not replaced?
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.
oh, I see, you're removing it in the util.ts change instead.
if (keyLower === "set-cookie") { | ||
// We need to remove the set-cookie header from the parsed headers because | ||
// it does not handle multiple set-cookie headers properly | ||
continue; |
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.
side note... I keep thinking that it would be nice if Object.entries(...)
(and the iterable pattern in general) would accept a filter function...
Object.entries(headers, filter);
...that could optimize this pattern more and make it so the collection only had to be iterated through once... That's for another time tho.
Replacing
delete X.y
withX.y = undefined
avoids killing any optimizations done by V8 to access the properties of an object faster.Subset of #1002