Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/react/src/__tests__/ReactChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,31 @@ describe('ReactChildren', () => {
});
});

it('does not throw on children without `_store`', async () => {
function ComponentRenderingFlattenedChildren({children}) {
return <div>{React.Children.toArray(children)}</div>;
}

const source = <div />;
const productionElement = {};
Object.entries(source).forEach(([key, value]) => {
if (key !== '_owner' && key !== '_store') {
productionElement[key] = value;
}
});
Comment on lines +1049 to +1053
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way this test case needs to be contrived signals that this mix of environments should really not be supported. We could consider adding build types to the version checks to prevent apps from relying on these setups in the future.

Copy link
Collaborator

@eps1lon eps1lon Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect you encounter this in development when you use 3rd party libraries that only have a single entrypoint with JSX compiled for production. Would require a lot of heavy lifting if we require libraries to ship both dev and prod entrypoints.

Object.freeze(productionElement);

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(
<ComponentRenderingFlattenedChildren>
{productionElement}
</ComponentRenderingFlattenedChildren>,
);
});
});

it('should escape keys', () => {
const zero = <div key="1" />;
const one = <div key="1=::=2" />;
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,9 @@ export function cloneAndReplaceKey(oldElement, newKey) {
);
if (__DEV__) {
// The cloned element should inherit the original element's key validation.
clonedElement._store.validated = oldElement._store.validated;
if (oldElement._store) {
clonedElement._store.validated = oldElement._store.validated;
}
}
return clonedElement;
}
Expand Down
Loading