@@ -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 ,
@@ -1260,61 +1260,63 @@ export function updateCacheNodeOnPopstateRestoration(
1260
1260
1261
1261
const DEFERRED = Symbol ( )
1262
1262
1263
- type PendingDeferredRsc = Promise < React . ReactNode > & {
1263
+ type PendingDeferredRsc < T > = Promise < T > & {
1264
1264
status : 'pending'
1265
- resolve : ( value : React . ReactNode ) => void
1265
+ resolve : ( value : T ) => void
1266
1266
reject : ( error : any ) => void
1267
1267
tag : Symbol
1268
1268
}
1269
1269
1270
- type FulfilledDeferredRsc = Promise < React . ReactNode > & {
1270
+ type FulfilledDeferredRsc < T > = Promise < T > & {
1271
1271
status : 'fulfilled'
1272
- value : React . ReactNode
1273
- resolve : ( value : React . ReactNode ) => void
1272
+ value : T
1273
+ resolve : ( value : T ) => void
1274
1274
reject : ( error : any ) => void
1275
1275
tag : Symbol
1276
1276
}
1277
1277
1278
- type RejectedDeferredRsc = Promise < React . ReactNode > & {
1278
+ type RejectedDeferredRsc < T > = Promise < T > & {
1279
1279
status : 'rejected'
1280
1280
reason : any
1281
- resolve : ( value : React . ReactNode ) => void
1281
+ resolve : ( value : T ) => void
1282
1282
reject : ( error : any ) => void
1283
1283
tag : Symbol
1284
1284
}
1285
1285
1286
- type DeferredRsc =
1287
- | PendingDeferredRsc
1288
- | FulfilledDeferredRsc
1289
- | RejectedDeferredRsc
1286
+ type DeferredRsc < T extends React . ReactNode = React . ReactNode > =
1287
+ | PendingDeferredRsc < T >
1288
+ | FulfilledDeferredRsc < T >
1289
+ | RejectedDeferredRsc < T >
1290
1290
1291
1291
// This type exists to distinguish a DeferredRsc from a Flight promise. It's a
1292
1292
// compromise to avoid adding an extra field on every Cache Node, which would be
1293
1293
// awkward because the pre-PPR parts of codebase would need to account for it,
1294
1294
// too. We can remove it once type Cache Node type is more settled.
1295
1295
function isDeferredRsc ( value : any ) : value is DeferredRsc {
1296
- return value && value . tag === DEFERRED
1296
+ return value && typeof value === 'object' && value . tag === DEFERRED
1297
1297
}
1298
1298
1299
- function createDeferredRsc ( ) : PendingDeferredRsc {
1299
+ function createDeferredRsc <
1300
+ T extends React . ReactNode = React . ReactNode ,
1301
+ > ( ) : PendingDeferredRsc < T > {
1300
1302
let resolve : any
1301
1303
let reject : any
1302
- const pendingRsc = new Promise < React . ReactNode > ( ( res , rej ) => {
1304
+ const pendingRsc = new Promise < T > ( ( res , rej ) => {
1303
1305
resolve = res
1304
1306
reject = rej
1305
- } ) as PendingDeferredRsc
1307
+ } ) as PendingDeferredRsc < T >
1306
1308
pendingRsc . status = 'pending'
1307
- pendingRsc . resolve = ( value : React . ReactNode ) => {
1309
+ pendingRsc . resolve = ( value : T ) => {
1308
1310
if ( pendingRsc . status === 'pending' ) {
1309
- const fulfilledRsc : FulfilledDeferredRsc = pendingRsc as any
1311
+ const fulfilledRsc : FulfilledDeferredRsc < T > = pendingRsc as any
1310
1312
fulfilledRsc . status = 'fulfilled'
1311
1313
fulfilledRsc . value = value
1312
1314
resolve ( value )
1313
1315
}
1314
1316
}
1315
1317
pendingRsc . reject = ( error : any ) => {
1316
1318
if ( pendingRsc . status === 'pending' ) {
1317
- const rejectedRsc : RejectedDeferredRsc = pendingRsc as any
1319
+ const rejectedRsc : RejectedDeferredRsc < T > = pendingRsc as any
1318
1320
rejectedRsc . status = 'rejected'
1319
1321
rejectedRsc . reason = error
1320
1322
reject ( error )
0 commit comments