Skip to content

Commit

Permalink
maybe gate only on !disableStringRefs????
Browse files Browse the repository at this point in the history
  • Loading branch information
josephsavona committed Apr 9, 2024
1 parent 9aedf71 commit 5162111
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions packages/react/src/__tests__/ReactElementClone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,39 +292,38 @@ describe('ReactElementClone', () => {
}
});

// @gate !disableStringRefs
it('should steal the ref if a new string ref is specified without an owner', async () => {
// Regression test for this specific feature combination calling cloneElement on an element
// without an owner
if (gate(flags => !flags.enableRefAsProp && !flags.disableStringRefs)) {
await expect(async () => {
// create an element without an owner
const element = React.createElement('div', {id: 'some-id'});
class Parent extends React.Component {
render() {
return <Child>{element}</Child>;
}
await expect(async () => {
// create an element without an owner
const element = React.createElement('div', {id: 'some-id'});
class Parent extends React.Component {
render() {
return <Child>{element}</Child>;
}
let child;
class Child extends React.Component {
render() {
child = this;
const clone = React.cloneElement(this.props.children, {
ref: 'xyz',
});
return <div>{clone}</div>;
}
}
let child;
class Child extends React.Component {
render() {
child = this;
const clone = React.cloneElement(this.props.children, {
ref: 'xyz',
});
return <div>{clone}</div>;
}
}

const root = ReactDOMClient.createRoot(document.createElement('div'));
await act(() => root.render(<Parent />));
expect(child.refs.xyz.tagName).toBe('DIV');
}).toErrorDev([
'Warning: Component "Child" contains the string ref "xyz". Support for ' +
'string refs will be removed in a future major release. We recommend ' +
'using useRef() or createRef() instead. Learn more about using refs ' +
'safely here: https://react.dev/link/strict-mode-string-ref',
]);
}
const root = ReactDOMClient.createRoot(document.createElement('div'));
await act(() => root.render(<Parent />));
expect(child.refs.xyz.tagName).toBe('DIV');
}).toErrorDev([
'Warning: Component "Child" contains the string ref "xyz". Support for ' +
'string refs will be removed in a future major release. We recommend ' +
'using useRef() or createRef() instead. Learn more about using refs ' +
'safely here: https://react.dev/link/strict-mode-string-ref',
]);
});

it('should overwrite props', async () => {
Expand Down

0 comments on commit 5162111

Please sign in to comment.