Skip to content

Commit 9ff42a8

Browse files
authored
Permit non-DEV Elements in React.Children w/ DEV (#32117)
1 parent 87c03a0 commit 9ff42a8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/react/src/__tests__/ReactChildren-test.js

+25
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,31 @@ describe('ReactChildren', () => {
10391039
});
10401040
});
10411041

1042+
it('does not throw on children without `_store`', async () => {
1043+
function ComponentRenderingFlattenedChildren({children}) {
1044+
return <div>{React.Children.toArray(children)}</div>;
1045+
}
1046+
1047+
const source = <div />;
1048+
const productionElement = {};
1049+
Object.entries(source).forEach(([key, value]) => {
1050+
if (key !== '_owner' && key !== '_store') {
1051+
productionElement[key] = value;
1052+
}
1053+
});
1054+
Object.freeze(productionElement);
1055+
1056+
const container = document.createElement('div');
1057+
const root = ReactDOMClient.createRoot(container);
1058+
await act(() => {
1059+
root.render(
1060+
<ComponentRenderingFlattenedChildren>
1061+
{productionElement}
1062+
</ComponentRenderingFlattenedChildren>,
1063+
);
1064+
});
1065+
});
1066+
10421067
it('should escape keys', () => {
10431068
const zero = <div key="1" />;
10441069
const one = <div key="1=::=2" />;

packages/react/src/jsx/ReactJSXElement.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,9 @@ export function cloneAndReplaceKey(oldElement, newKey) {
813813
);
814814
if (__DEV__) {
815815
// The cloned element should inherit the original element's key validation.
816-
clonedElement._store.validated = oldElement._store.validated;
816+
if (oldElement._store) {
817+
clonedElement._store.validated = oldElement._store.validated;
818+
}
817819
}
818820
return clonedElement;
819821
}

0 commit comments

Comments
 (0)