Skip to content

Commit 9d823db

Browse files
committed
jsx(): Treat __self and __source as normal props
These used to be reserved props because the classic React.createElement runtime passed this data as props, whereas the jsxDEV() runtime passes them as separate arguments. This brings us incrementally closer to being able to pass the props object directly through to React instead of cloning a subset into a new object. The React.createElement runtime is unaffected.
1 parent 30e2938 commit 9d823db

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/react/src/__tests__/ReactElementValidator-test.internal.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,26 @@ describe('ReactElementValidator', () => {
569569
React.createElement(Lazy);
570570
expect(didCall).toBe(false);
571571
});
572+
573+
it('__self and __source are treated as normal props', async () => {
574+
// These used to be reserved props because the classic React.createElement
575+
// runtime passed this data as props, whereas the jsxDEV() runtime passes
576+
// them as separate arguments.
577+
function Child({__self, __source}) {
578+
return __self + __source;
579+
}
580+
581+
const container = document.createElement('div');
582+
const root = ReactDOMClient.createRoot(container);
583+
// NOTE: The Babel transform treats the presence of these props as a syntax
584+
// error but theoretically it doesn't have to. Using spread here to
585+
// circumvent the syntax error and demonstrate that the runtime
586+
// doesn't care.
587+
const props = {
588+
__self: 'Hello ',
589+
__source: 'world!',
590+
};
591+
await act(() => root.render(<Child {...props} />));
592+
expect(container.textContent).toBe('Hello world!');
593+
});
572594
});

packages/react/src/jsx/ReactJSXElement.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
1616
const RESERVED_PROPS = {
1717
key: true,
1818
ref: true,
19-
__self: true,
20-
__source: true,
2119
};
2220

2321
let specialPropKeyWarningShown;

0 commit comments

Comments
 (0)