Skip to content

Commit 1c532d5

Browse files
committed
Avoid unhandled rejection errors for Promises that we intentionally ignore
In the final passes, we ignore the newly generated Promises and use the previous ones. This ensures that if those generate errors, that we intentionally ignore those.
1 parent ad90b87 commit 1c532d5

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

packages/react-reconciler/src/ReactFiberHooks.new.js

+7
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,8 @@ if (enableUseMemoCacheHook) {
768768
};
769769
}
770770

771+
function noop(): void {}
772+
771773
function use<T>(usable: Usable<T>): T {
772774
if (usable !== null && typeof usable === 'object') {
773775
// $FlowFixMe[method-unbinding]
@@ -793,6 +795,11 @@ function use<T>(usable: Usable<T>): T {
793795
index,
794796
);
795797
if (prevThenableAtIndex !== null) {
798+
if (thenable !== prevThenableAtIndex) {
799+
// Avoid an unhandled rejection errors for the Promises that we'll
800+
// intentionally ignore.
801+
thenable.then(noop, noop);
802+
}
796803
switch (prevThenableAtIndex.status) {
797804
case 'fulfilled': {
798805
const fulfilledValue: T = prevThenableAtIndex.value;

packages/react-reconciler/src/ReactFiberHooks.old.js

+7
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,8 @@ if (enableUseMemoCacheHook) {
768768
};
769769
}
770770

771+
function noop(): void {}
772+
771773
function use<T>(usable: Usable<T>): T {
772774
if (usable !== null && typeof usable === 'object') {
773775
// $FlowFixMe[method-unbinding]
@@ -793,6 +795,11 @@ function use<T>(usable: Usable<T>): T {
793795
index,
794796
);
795797
if (prevThenableAtIndex !== null) {
798+
if (thenable !== prevThenableAtIndex) {
799+
// Avoid an unhandled rejection errors for the Promises that we'll
800+
// intentionally ignore.
801+
thenable.then(noop, noop);
802+
}
796803
switch (prevThenableAtIndex.status) {
797804
case 'fulfilled': {
798805
const fulfilledValue: T = prevThenableAtIndex.value;

packages/react-server/src/ReactFizzHooks.js

+5
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ function use<T>(usable: Usable<T>): T {
610610
index,
611611
);
612612
if (prevThenableAtIndex !== null) {
613+
if (thenable !== prevThenableAtIndex) {
614+
// Avoid an unhandled rejection errors for the Promises that we'll
615+
// intentionally ignore.
616+
thenable.then(noop, noop);
617+
}
613618
switch (prevThenableAtIndex.status) {
614619
case 'fulfilled': {
615620
const fulfilledValue: T = prevThenableAtIndex.value;

packages/react-server/src/ReactFlightHooks.js

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ function useId(): string {
121121
return ':' + currentRequest.identifierPrefix + 'S' + id.toString(32) + ':';
122122
}
123123

124+
function noop(): void {}
125+
124126
function use<T>(usable: Usable<T>): T {
125127
if (usable !== null && typeof usable === 'object') {
126128
// $FlowFixMe[method-unbinding]
@@ -147,6 +149,11 @@ function use<T>(usable: Usable<T>): T {
147149
index,
148150
);
149151
if (prevThenableAtIndex !== null) {
152+
if (thenable !== prevThenableAtIndex) {
153+
// Avoid an unhandled rejection errors for the Promises that we'll
154+
// intentionally ignore.
155+
thenable.then(noop, noop);
156+
}
150157
switch (prevThenableAtIndex.status) {
151158
case 'fulfilled': {
152159
const fulfilledValue: T = prevThenableAtIndex.value;

0 commit comments

Comments
 (0)