-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Utilize Promise.withResolvers #56764
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Diff detailsDiff for page.jsDiff too large to display Diff for edge-ssr.jsDiff too large to display |
@@ -794,16 +794,3 @@ export async function getImageSize( | |||
const { width, height } = imageSizeOf(buffer) | |||
return { width, height } | |||
} | |||
|
|||
export class Deferred<T> { |
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 imported 🤷🏻
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 think this was leftover from something long ago, so it can be removed 😅
let resolver: (cacheEntry: ResponseCacheEntry | null) => void = () => {} | ||
let rejecter: (error: Error) => void = () => {} | ||
const promise: Promise<ResponseCacheEntry | null> = new Promise( |
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.
Now we can use the types returned by Promise.withResolvers
!
this.setDevReady!() | ||
|
||
this.ready?.resolve() | ||
this.ready = 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.
Any reason this is set to 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.
Because we didn't want to permit resolving more than once or rejecting after the value was resolved, this setting it to undefined
was to act as a signal that the "value isn't of use anymore". Ideally, we'd want to do if (this.ready) await this.ready.promise
to improve the performance, as it would allow us to avoid the await
and subsequent yielding to the event loop.
Tests Passed |
This utilizes
Promise.withResolvers
in a few places where it was done the old way. This also rearranges some imports and typings.