From 51621113edbf82f60c4ad7c2ff4e9c5bb63e2a17 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Tue, 9 Apr 2024 13:35:39 -0700 Subject: [PATCH] maybe gate only on !disableStringRefs???? --- .../src/__tests__/ReactElementClone-test.js | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/react/src/__tests__/ReactElementClone-test.js b/packages/react/src/__tests__/ReactElementClone-test.js index 4a350103d22cd..a8cf751635149 100644 --- a/packages/react/src/__tests__/ReactElementClone-test.js +++ b/packages/react/src/__tests__/ReactElementClone-test.js @@ -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 {element}; - } + await expect(async () => { + // create an element without an owner + const element = React.createElement('div', {id: 'some-id'}); + class Parent extends React.Component { + render() { + return {element}; } - let child; - class Child extends React.Component { - render() { - child = this; - const clone = React.cloneElement(this.props.children, { - ref: 'xyz', - }); - return
{clone}
; - } + } + let child; + class Child extends React.Component { + render() { + child = this; + const clone = React.cloneElement(this.props.children, { + ref: 'xyz', + }); + return
{clone}
; } + } - const root = ReactDOMClient.createRoot(document.createElement('div')); - await act(() => root.render()); - 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()); + 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 () => {