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

[Flight] Don't warn for key, but error for ref #19986

Merged
merged 3 commits into from
Oct 9, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Don't warn for key/ref getters
  • Loading branch information
sebmarkbage committed Oct 8, 2020
commit 6f6f032cfbb77da1861559705acc997cfb86bfd2
9 changes: 9 additions & 0 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
@@ -217,6 +217,15 @@ describe('ReactFlight', () => {
);
});

it('should NOT warn in DEV for key/ref getters', () => {
const transport = ReactNoopFlightServer.render(
<div key="a" ref={() => {}} />,
);
act(() => {
ReactNoop.render(ReactNoopFlightClient.read(transport));
});
});

it('should warn in DEV if an object with symbols is passed to a host component', () => {
expect(() => {
const transport = ReactNoopFlightServer.render(
11 changes: 10 additions & 1 deletion packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
@@ -218,7 +218,16 @@ function isSimpleObject(object): boolean {
const names = Object.getOwnPropertyNames(object);
for (let i = 0; i < names.length; i++) {
const descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
if (!descriptor || !descriptor.enumerable) {
if (!descriptor) {
return false;
}
if (!descriptor.enumerable) {
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
// React adds key and ref getters to props objects to issue warnings.
// Those getters will not be transferred to the client, but that's ok,
// so we'll special case them.
continue;
}
return false;
}
}