@samitouri / QOS-React / commits / 9ff42a8798

Permit non-`DEV` Elements in `React.Children` w/ `DEV` (#32117)

Timothy Yung committed Jan 30, 2025 at 22:59 UTC 9ff42a8798863c995523e284142b47e3cdfaee80
2 files changed +28 -1
packages/react/src/__tests__/ReactChildren-test.js
+25
@@ -1039,6 +1039,31 @@ describe('ReactChildren', () => {
1039 });
1040 });
1041
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 +
1067 it('should escape keys', () => {
1068 const zero = <div key="1" />;
1069 const one = <div key="1=::=2" />;
packages/react/src/jsx/ReactJSXElement.js
+3 -1
@@ -813,7 +813,9 @@ export function cloneAndReplaceKey(oldElement, newKey) {
813 );
814 if (__DEV__) {
815 // 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 + }
819 }
820 return clonedElement;
821 }