@@ -979,7 +979,7 @@ function createPendingCacheNode(
979
979
: // We're navigating without a prefetch. We don't have a `loading` to display now,
980
980
// but we might get one from the dynamic response. We'll fulfill this promise
981
981
// when we receive that.
982
- ( createDeferredRsc ( ) as Promise < LoadingModuleData > )
982
+ createDeferredRsc < LoadingModuleData > ( )
983
983
return {
984
984
lazyData : null ,
985
985
parallelRoutes : parallelRoutes ,
@@ -1254,61 +1254,63 @@ export function updateCacheNodeOnPopstateRestoration(
1254
1254
1255
1255
const DEFERRED = Symbol ( )
1256
1256
1257
- type PendingDeferredRsc = Promise < React . ReactNode > & {
1257
+ type PendingDeferredRsc < T > = Promise < T > & {
1258
1258
status : 'pending'
1259
- resolve : ( value : React . ReactNode ) => void
1259
+ resolve : ( value : T ) => void
1260
1260
reject : ( error : any ) => void
1261
1261
tag : Symbol
1262
1262
}
1263
1263
1264
- type FulfilledDeferredRsc = Promise < React . ReactNode > & {
1264
+ type FulfilledDeferredRsc < T > = Promise < T > & {
1265
1265
status : 'fulfilled'
1266
- value : React . ReactNode
1267
- resolve : ( value : React . ReactNode ) => void
1266
+ value : T
1267
+ resolve : ( value : T ) => void
1268
1268
reject : ( error : any ) => void
1269
1269
tag : Symbol
1270
1270
}
1271
1271
1272
- type RejectedDeferredRsc = Promise < React . ReactNode > & {
1272
+ type RejectedDeferredRsc < T > = Promise < T > & {
1273
1273
status : 'rejected'
1274
1274
reason : any
1275
- resolve : ( value : React . ReactNode ) => void
1275
+ resolve : ( value : T ) => void
1276
1276
reject : ( error : any ) => void
1277
1277
tag : Symbol
1278
1278
}
1279
1279
1280
- type DeferredRsc =
1281
- | PendingDeferredRsc
1282
- | FulfilledDeferredRsc
1283
- | RejectedDeferredRsc
1280
+ type DeferredRsc < T extends React . ReactNode = React . ReactNode > =
1281
+ | PendingDeferredRsc < T >
1282
+ | FulfilledDeferredRsc < T >
1283
+ | RejectedDeferredRsc < T >
1284
1284
1285
1285
// This type exists to distinguish a DeferredRsc from a Flight promise. It's a
1286
1286
// compromise to avoid adding an extra field on every Cache Node, which would be
1287
1287
// awkward because the pre-PPR parts of codebase would need to account for it,
1288
1288
// too. We can remove it once type Cache Node type is more settled.
1289
1289
function isDeferredRsc ( value : any ) : value is DeferredRsc {
1290
- return value && value . tag === DEFERRED
1290
+ return value && typeof value === 'object' && value . tag === DEFERRED
1291
1291
}
1292
1292
1293
- function createDeferredRsc ( ) : PendingDeferredRsc {
1293
+ function createDeferredRsc <
1294
+ T extends React . ReactNode = React . ReactNode ,
1295
+ > ( ) : PendingDeferredRsc < T > {
1294
1296
let resolve : any
1295
1297
let reject : any
1296
- const pendingRsc = new Promise < React . ReactNode > ( ( res , rej ) => {
1298
+ const pendingRsc = new Promise < T > ( ( res , rej ) => {
1297
1299
resolve = res
1298
1300
reject = rej
1299
- } ) as PendingDeferredRsc
1301
+ } ) as PendingDeferredRsc < T >
1300
1302
pendingRsc . status = 'pending'
1301
- pendingRsc . resolve = ( value : React . ReactNode ) => {
1303
+ pendingRsc . resolve = ( value : T ) => {
1302
1304
if ( pendingRsc . status === 'pending' ) {
1303
- const fulfilledRsc : FulfilledDeferredRsc = pendingRsc as any
1305
+ const fulfilledRsc : FulfilledDeferredRsc < T > = pendingRsc as any
1304
1306
fulfilledRsc . status = 'fulfilled'
1305
1307
fulfilledRsc . value = value
1306
1308
resolve ( value )
1307
1309
}
1308
1310
}
1309
1311
pendingRsc . reject = ( error : any ) => {
1310
1312
if ( pendingRsc . status === 'pending' ) {
1311
- const rejectedRsc : RejectedDeferredRsc = pendingRsc as any
1313
+ const rejectedRsc : RejectedDeferredRsc < T > = pendingRsc as any
1312
1314
rejectedRsc . status = 'rejected'
1313
1315
rejectedRsc . reason = error
1314
1316
reject ( error )
0 commit comments