@@ -2013,6 +2013,8 @@ function resetSuspendedWorkLoopOnUnwind(fiber: Fiber) {
2013
2013
resetChildReconcilerOnUnwind ( ) ;
2014
2014
}
2015
2015
2016
+ let didWarnForThrowAPromise = false ;
2017
+
2016
2018
function handleThrow ( root : FiberRoot , thrownValue : any ) : void {
2017
2019
// A component threw an exception. Usually this is because it suspended, but
2018
2020
// it also includes regular program errors.
@@ -2066,19 +2068,34 @@ function handleThrow(root: FiberRoot, thrownValue: any): void {
2066
2068
// case where we think this should happen.
2067
2069
workInProgressSuspendedReason = SuspendedOnHydration ;
2068
2070
} else {
2069
- // This is a regular error.
2070
2071
const isWakeable =
2071
2072
thrownValue !== null &&
2072
2073
typeof thrownValue === 'object' &&
2073
2074
typeof thrownValue . then === 'function' ;
2074
-
2075
- workInProgressSuspendedReason = isWakeable
2076
- ? // A wakeable object was thrown by a legacy Suspense implementation.
2077
- // This has slightly different behavior than suspending with `use`.
2078
- SuspendedOnDeprecatedThrowPromise
2079
- : // This is a regular error. If something earlier in the component already
2080
- // suspended, we must clear the thenable state to unblock the work loop.
2081
- SuspendedOnError ;
2075
+ if ( isWakeable ) {
2076
+ // A wakeable object was thrown by a legacy Suspense implementation.
2077
+ // This has slightly different behavior than suspending with `use`.
2078
+ workInProgressSuspendedReason = SuspendedOnDeprecatedThrowPromise ;
2079
+ if ( __DEV__ ) {
2080
+ if ( ! didWarnForThrowAPromise && workInProgress !== null ) {
2081
+ didWarnForThrowAPromise = true ;
2082
+ const componentName =
2083
+ getComponentNameFromFiber ( workInProgress ) || 'unknown' ;
2084
+ runWithFiberInDEV ( workInProgress , ( ) => {
2085
+ console . warn (
2086
+ 'Throwing a Promise to cause it to suspend is deprecated in React.\n' +
2087
+ 'Please update your library to call use(promise) instead.\n' +
2088
+ 'See https://react.dev/reference/react/use\n\n in %s' ,
2089
+ componentName ,
2090
+ ) ;
2091
+ } ) ;
2092
+ }
2093
+ }
2094
+ } else {
2095
+ // This is a regular error. If something earlier in the component already
2096
+ // suspended, we must clear the thenable state to unblock the work loop.
2097
+ workInProgressSuspendedReason = SuspendedOnError ;
2098
+ }
2082
2099
}
2083
2100
2084
2101
workInProgressThrownValue = thrownValue ;
0 commit comments