-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(nextjs): Use Proxies to wrap to preserve static methods #7002
Conversation
return async function (this: unknown, ...args: Parameters<H>): Promise<ReturnType<H>> { | ||
const req = args[0]; | ||
return new Proxy(handler, { | ||
apply: async (wrappingTarget, thisArg, args: Parameters<H>) => { |
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 this supported, e.g. having an async apply
? Just wondering :D I guess we don't even really need it here, though? Or am I missing something?
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.
Not sure about the term "supported" but from my testing, using an async function just seems to return a promise which is about what I would expect to happen. We definitely need it here though because we wanna await the result so that the events are flushed.
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.
Ah, good, if it works then 👍 maybe it is just a restriction for get
based proxies, I vaguely remember having issues with such a thing in the past. But all good then, nice!
size-limit report 📦
|
// Log a warning if the user is still manually wrapping their route in `withSentry`. Doesn't work in cases where | ||
// there's been an intermediate wrapper (like `withSentryAPI(someOtherWrapper(withSentry(handler)))`) but should catch | ||
// most cases. Only runs once per route. (Note: Such double-wrapping isn't harmful, but we'll eventually deprecate and remove `withSentry`, so | ||
// best to get people to stop using it.) |
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 decided to remove this because it would have been a pain to get working with proxies and it doesn't hurt anyone not to have this log message.
Fixes #6931
Our (automatic) wrapper functions were hiding away any additional fields users defined on the wrapping targets. This PR fixes this by using
Proxy
which will preserve the rest of the fields.