Skip to content
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

Merged
merged 2 commits into from
Jan 31, 2023

Conversation

lforst
Copy link
Member

@lforst lforst commented Jan 31, 2023

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.

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>) => {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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!

@github-actions
Copy link
Contributor

github-actions bot commented Jan 31, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.88 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 61.57 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.54 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 54.88 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.29 KB (0%)
@sentry/browser - Webpack (minified) 66.37 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.31 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.6 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.79 KB (0%)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.08 KB (0%)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 44.17 KB (0%)
@sentry/replay - Webpack (gzipped + minified) 38.92 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 61.52 KB (0%)

Comment on lines -32 to -35
// 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.)
Copy link
Member Author

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.

@lforst lforst marked this pull request as ready for review January 31, 2023 16:48
@lforst lforst requested review from mydea and AbhiPrasad January 31, 2023 16:49
@lforst lforst merged commit fd4db0d into develop Jan 31, 2023
@lforst lforst deleted the lforst-use-proxy branch January 31, 2023 17:38
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.

Next.js auto instrumentation hides properties of wrapped api routes
3 participants