You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Throw a better error when Lazy/Promise is used in React.Children (#28280)
We could in theory actually support this case by throwing a Promise when
it's used inside a render. Allowing it to be synchronously unwrapped.
However, it's a bit sketchy because we officially only support this in
the render's child position or in `use()`.
Another alternative could be to actually pass the Promise/Lazy to the
callback so that you can reason about it and just return it again or
even unwrapping with `use()` - at least for the forEach case maybe.
DiffTrain build for [e41ee9e](e41ee9e)
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
"Objects are not valid as a React child (found: "+
252
-
("[object Object]"===array
253
-
? "object with keys {"+Object.keys(children).join(", ")+"}"
254
-
: array)+
255
-
"). If you meant to render a collection of children, use an array instead."
256
-
))
252
+
elseif("object"===type){
253
+
array=String(children);
254
+
if("function"===typeofchildren.then)
255
+
throwError(
256
+
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
257
+
);
258
+
throwError(
259
+
"Objects are not valid as a React child (found: "+
260
+
("[object Object]"===array
261
+
? "object with keys {"+Object.keys(children).join(", ")+"}"
262
+
: array)+
263
+
"). If you meant to render a collection of children, use an array instead."
257
264
);
265
+
}
258
266
returninvokeCallback;
259
267
}
260
268
functionmapChildren(children,func,context){
@@ -570,4 +578,4 @@ exports.useSyncExternalStore = function (
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
"Objects are not valid as a React child (found: "+
223
-
("[object Object]"===array
224
-
? "object with keys {"+Object.keys(children).join(", ")+"}"
225
-
: array)+
226
-
"). If you meant to render a collection of children, use an array instead."
227
-
))
223
+
elseif("object"===type){
224
+
array=String(children);
225
+
if("function"===typeofchildren.then)
226
+
throwError(
227
+
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
228
+
);
229
+
throwError(
230
+
"Objects are not valid as a React child (found: "+
231
+
("[object Object]"===array
232
+
? "object with keys {"+Object.keys(children).join(", ")+"}"
233
+
: array)+
234
+
"). If you meant to render a collection of children, use an array instead."
228
235
);
236
+
}
229
237
returninvokeCallback;
230
238
}
231
239
functionmapChildren(children,func,context){
@@ -562,4 +570,4 @@ exports.useSyncExternalStore = function (
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
"Objects are not valid as a React child (found: "+
256
-
("[object Object]"===array
257
-
? "object with keys {"+Object.keys(children).join(", ")+"}"
258
-
: array)+
259
-
"). If you meant to render a collection of children, use an array instead."
260
-
))
256
+
elseif("object"===type){
257
+
array=String(children);
258
+
if("function"===typeofchildren.then)
259
+
throwError(
260
+
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
261
+
);
262
+
throwError(
263
+
"Objects are not valid as a React child (found: "+
264
+
("[object Object]"===array
265
+
? "object with keys {"+Object.keys(children).join(", ")+"}"
266
+
: array)+
267
+
"). If you meant to render a collection of children, use an array instead."
261
268
);
269
+
}
262
270
returninvokeCallback;
263
271
}
264
272
functionmapChildren(children,func,context){
@@ -574,7 +582,7 @@ exports.useSyncExternalStore = function (
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
"Objects are not valid as a React child (found: "+
227
-
("[object Object]"===array
228
-
? "object with keys {"+Object.keys(children).join(", ")+"}"
229
-
: array)+
230
-
"). If you meant to render a collection of children, use an array instead."
231
-
))
227
+
elseif("object"===type){
228
+
array=String(children);
229
+
if("function"===typeofchildren.then)
230
+
throwError(
231
+
"Cannot render an Async Component, Promise or React.Lazy inside React.Children. We recommend not iterating over children and just rendering them plain."
232
+
);
233
+
throwError(
234
+
"Objects are not valid as a React child (found: "+
235
+
("[object Object]"===array
236
+
? "object with keys {"+Object.keys(children).join(", ")+"}"
237
+
: array)+
238
+
"). If you meant to render a collection of children, use an array instead."
232
239
);
240
+
}
233
241
returninvokeCallback;
234
242
}
235
243
functionmapChildren(children,func,context){
@@ -566,7 +574,7 @@ exports.useSyncExternalStore = function (
0 commit comments