Skip to content

Commit 04dde74

Browse files
Merge branch 'canary' into scripts-fs-extra
2 parents 206c661 + 255cc9b commit 04dde74

File tree

12 files changed

+35
-63
lines changed

12 files changed

+35
-63
lines changed

packages/next/src/build/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import '../server/require-hook'
2121
import '../server/node-polyfill-fetch'
2222
import '../server/node-polyfill-crypto'
2323
import '../server/node-environment'
24-
import '../lib/polyfill-promise-with-resolvers'
2524

2625
import { green, yellow, red, cyan, bold, underline } from '../lib/picocolors'
2726
import getGzipSize from 'next/dist/compiled/gzip-size'

packages/next/src/export/worker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
import '../server/node-polyfill-fetch'
1212
import '../server/node-polyfill-web-streams'
1313
import '../server/node-environment'
14-
import '../lib/polyfill-promise-with-resolvers'
1514

1615
process.env.NEXT_IS_EXPORT_WORKER = 'true'
1716

packages/next/src/lib/batcher.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
// This takes advantage of `Promise.withResolvers` which is polyfilled in
2-
// this imported module.
3-
import './polyfill-promise-with-resolvers'
4-
51
import type { SchedulerFn } from '../server/lib/schedule-on-next-tick'
2+
import { DetachedPromise } from './detached-promise'
63

74
type CacheKeyFn<K, C extends string | number | null> = (
85
key: K
@@ -72,7 +69,7 @@ export class Batcher<K, V, C extends string | number | null> {
7269
const pending = this.pending.get(cacheKey)
7370
if (pending) return pending
7471

75-
const { promise, resolve, reject } = Promise.withResolvers<V>()
72+
const { promise, resolve, reject } = new DetachedPromise<V>()
7673
this.pending.set(cacheKey, promise)
7774

7875
this.schedulerFn(async () => {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* A `Promise.withResolvers` implementation that exposes the `resolve` and
3+
* `reject` functions on a `Promise`.
4+
*
5+
* @see https://tc39.es/proposal-promise-with-resolvers/
6+
*/
7+
export class DetachedPromise<T = any> {
8+
public readonly resolve: (value: T | PromiseLike<T>) => void
9+
public readonly reject: (reason: any) => void
10+
public readonly promise: Promise<T>
11+
12+
constructor() {
13+
let resolve: (value: T | PromiseLike<T>) => void
14+
let reject: (reason: any) => void
15+
16+
// Create the promise and assign the resolvers to the object.
17+
this.promise = new Promise<T>((res, rej) => {
18+
resolve = res
19+
reject = rej
20+
})
21+
22+
// We know that resolvers is defined because the Promise constructor runs
23+
// synchronously.
24+
this.resolve = resolve!
25+
this.reject = reject!
26+
}
27+
}

packages/next/src/lib/polyfill-promise-with-resolvers.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/next/src/server/dev/next-dev-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { DefaultFileReader } from '../future/route-matcher-providers/dev/helpers
6161
import { NextBuildContext } from '../../build/build-context'
6262
import LRUCache from 'next/dist/compiled/lru-cache'
6363
import { getMiddlewareRouteMatcher } from '../../shared/lib/router/utils/middleware-route-matcher'
64+
import { DetachedPromise } from '../../lib/detached-promise'
6465

6566
// Load ReactDevOverlay only when needed
6667
let ReactDevOverlayImpl: FunctionComponent
@@ -89,7 +90,7 @@ export default class DevServer extends Server {
8990
* The promise that resolves when the server is ready. When this is unset
9091
* the server is ready.
9192
*/
92-
private ready? = Promise.withResolvers<void>()
93+
private ready? = new DetachedPromise<void>()
9394
protected sortedRoutes?: string[]
9495
private pagesDir?: string
9596
private appDir?: string

packages/next/src/server/dev/static-paths-worker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { NextConfigComplete } from '../config-shared'
33
import '../require-hook'
44
import '../node-polyfill-fetch'
55
import '../node-environment'
6-
import '../../lib/polyfill-promise-with-resolvers'
76

87
import {
98
buildAppStaticPaths,

packages/next/src/server/future/route-matcher-managers/default-route-matcher-manager.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// This takes advantage of `Promise.withResolvers` which is polyfilled in
2-
// this imported module.
3-
import '../../../lib/polyfill-promise-with-resolvers'
4-
51
import { isDynamicRoute } from '../../../shared/lib/router/utils'
62
import type { RouteKind } from '../route-kind'
73
import type { RouteMatch } from '../route-matches/route-match'
@@ -12,6 +8,7 @@ import type { MatchOptions, RouteMatcherManager } from './route-matcher-manager'
128
import { getSortedRoutes } from '../../../shared/lib/router/utils'
139
import { LocaleRouteMatcher } from '../route-matchers/locale-route-matcher'
1410
import { ensureLeadingSlash } from '../../../shared/lib/page-path/ensure-leading-slash'
11+
import { DetachedPromise } from '../../../lib/detached-promise'
1512

1613
interface RouteMatchers {
1714
static: ReadonlyArray<RouteMatcher>
@@ -46,7 +43,7 @@ export class DefaultRouteMatcherManager implements RouteMatcherManager {
4643

4744
private previousMatchers: ReadonlyArray<RouteMatcher> = []
4845
public async reload() {
49-
const { promise, resolve, reject } = Promise.withResolvers<void>()
46+
const { promise, resolve, reject } = new DetachedPromise<void>()
5047
this.waitTillReadyPromise = promise
5148

5249
// Grab the compilation ID for this run, we'll verify it at the end to

packages/next/src/server/lib/router-server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { NextUrlWithParsedQuery } from '../request-meta'
66
import '../node-polyfill-fetch'
77
import '../node-environment'
88
import '../require-hook'
9-
import '../../lib/polyfill-promise-with-resolvers'
109

1110
import url from 'url'
1211
import path from 'path'

packages/next/src/server/next-server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import './node-polyfill-fetch'
44
import './node-polyfill-form'
55
import './node-polyfill-web-streams'
66
import './node-polyfill-crypto'
7-
import '../lib/polyfill-promise-with-resolvers'
87

98
import type { TLSSocket } from 'tls'
109
import type { CacheFs } from '../shared/lib/utils'

packages/next/src/server/response-cache/web.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DetachedPromise } from '../../lib/detached-promise'
12
import type { ResponseCacheEntry, ResponseGenerator } from './types'
23

34
/**
@@ -45,7 +46,7 @@ export default class WebResponseCache {
4546
promise,
4647
resolve: resolver,
4748
reject: rejecter,
48-
} = Promise.withResolvers<ResponseCacheEntry | null>()
49+
} = new DetachedPromise<ResponseCacheEntry | null>()
4950
if (pendingResponseKey) {
5051
this.pendingResponses.set(pendingResponseKey, promise)
5152
}

packages/next/types/index.d.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,6 @@ declare global {
318318
randomUUID(): string
319319
}
320320

321-
// TODO: remove this polyfill when it is adopted into the spec.
322-
interface PromiseConstructor {
323-
/**
324-
* Creates a new promise with exposed resolvers to resolve/reject. This will
325-
* be adopted into the spec as `Promise.withResolvers`.
326-
*
327-
* @see https://tc39.es/proposal-promise-with-resolvers/
328-
*/
329-
withResolvers<T>(): {
330-
promise: Promise<T>
331-
resolve: (value: T | PromiseLike<T>) => void
332-
reject: (reason?: unknown) => void
333-
}
334-
}
335-
336321
var __NEXT_HTTP_AGENT_OPTIONS: { keepAlive?: boolean } | undefined
337322
var __NEXT_UNDICI_AGENT_SET: boolean
338323
var __NEXT_HTTP_AGENT: HttpAgent

0 commit comments

Comments
 (0)