Skip to content

Commit 6f6f032

Browse files
committed
Don't warn for key/ref getters
1 parent 7e09c2d commit 6f6f032

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ describe('ReactFlight', () => {
217217
);
218218
});
219219

220+
it('should NOT warn in DEV for key/ref getters', () => {
221+
const transport = ReactNoopFlightServer.render(
222+
<div key="a" ref={() => {}} />,
223+
);
224+
act(() => {
225+
ReactNoop.render(ReactNoopFlightClient.read(transport));
226+
});
227+
});
228+
220229
it('should warn in DEV if an object with symbols is passed to a host component', () => {
221230
expect(() => {
222231
const transport = ReactNoopFlightServer.render(

packages/react-server/src/ReactFlightServer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,16 @@ function isSimpleObject(object): boolean {
218218
const names = Object.getOwnPropertyNames(object);
219219
for (let i = 0; i < names.length; i++) {
220220
const descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
221-
if (!descriptor || !descriptor.enumerable) {
221+
if (!descriptor) {
222+
return false;
223+
}
224+
if (!descriptor.enumerable) {
225+
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
226+
// React adds key and ref getters to props objects to issue warnings.
227+
// Those getters will not be transferred to the client, but that's ok,
228+
// so we'll special case them.
229+
continue;
230+
}
222231
return false;
223232
}
224233
}

0 commit comments

Comments
 (0)