@@ -42,19 +42,6 @@ describe('ReactComponent', () => {
4242 } ) . toThrowError ( / T a r g e t c o n t a i n e r i s n o t a D O M e l e m e n t ./ ) ;
4343 } ) ;
4444
45- // @gate !disableStringRefs
46- it ( 'should throw when supplying a string ref outside of render method' , async ( ) => {
47- const container = document . createElement ( 'div' ) ;
48- const root = ReactDOMClient . createRoot ( container ) ;
49- await expect (
50- act ( ( ) => {
51- root . render ( < div ref = "badDiv" /> ) ;
52- } ) ,
53- // TODO: This throws an AggregateError. Need to update test infra to
54- // support matching against AggregateError.
55- ) . rejects . toThrow ( ) ;
56- } ) ;
57-
5845 it ( 'should throw (in dev) when children are mutated during render' , async ( ) => {
5946 function Wrapper ( props ) {
6047 props . children [ 1 ] = < p key = { 1 } /> ; // Mutation is illegal
@@ -132,105 +119,6 @@ describe('ReactComponent', () => {
132119 }
133120 } ) ;
134121
135- // @gate !disableStringRefs
136- it ( 'string refs do not detach and reattach on every render' , async ( ) => {
137- let refVal ;
138- class Child extends React . Component {
139- componentDidUpdate ( ) {
140- // The parent ref should still be attached because it hasn't changed
141- // since the last render. If the ref had changed, then this would be
142- // undefined because refs are attached during the same phase (layout)
143- // as componentDidUpdate, in child -> parent order. So the new parent
144- // ref wouldn't have attached yet.
145- refVal = this . props . contextRef ( ) ;
146- }
147-
148- render ( ) {
149- if ( this . props . show ) {
150- return < div > child</ div > ;
151- }
152- }
153- }
154-
155- class Parent extends React . Component {
156- render ( ) {
157- return (
158- < div id = "test-root" ref = "root" >
159- < Child
160- contextRef = { ( ) => this . refs . root }
161- show = { this . props . showChild }
162- />
163- </ div >
164- ) ;
165- }
166- }
167-
168- const container = document . createElement ( 'div' ) ;
169- const root = ReactDOMClient . createRoot ( container ) ;
170-
171- await act ( ( ) => {
172- root . render ( < Parent /> ) ;
173- } ) ;
174-
175- assertConsoleErrorDev ( [ 'contains the string ref' ] ) ;
176-
177- expect ( refVal ) . toBe ( undefined ) ;
178- await act ( ( ) => {
179- root . render ( < Parent showChild = { true } /> ) ;
180- } ) ;
181- expect ( refVal ) . toBe ( container . querySelector ( '#test-root' ) ) ;
182- } ) ;
183-
184- // @gate !disableStringRefs
185- it ( 'should support string refs on owned components' , async ( ) => {
186- const innerObj = { } ;
187- const outerObj = { } ;
188-
189- class Wrapper extends React . Component {
190- getObject = ( ) => {
191- return this . props . object ;
192- } ;
193-
194- render ( ) {
195- return < div > { this . props . children } </ div > ;
196- }
197- }
198-
199- class Component extends React . Component {
200- render ( ) {
201- const inner = < Wrapper object = { innerObj } ref = "inner" /> ;
202- const outer = (
203- < Wrapper object = { outerObj } ref = "outer" >
204- { inner }
205- </ Wrapper >
206- ) ;
207- return outer ;
208- }
209-
210- componentDidMount ( ) {
211- expect ( this . refs . inner . getObject ( ) ) . toEqual ( innerObj ) ;
212- expect ( this . refs . outer . getObject ( ) ) . toEqual ( outerObj ) ;
213- }
214- }
215-
216- const container = document . createElement ( 'div' ) ;
217- const root = ReactDOMClient . createRoot ( container ) ;
218- await expect ( async ( ) => {
219- await act ( ( ) => {
220- root . render ( < Component /> ) ;
221- } ) ;
222- } ) . toErrorDev ( [
223- 'Component "Component" contains the string ref "inner". ' +
224- 'Support for string refs will be removed in a future major release. ' +
225- 'We recommend using useRef() or createRef() instead. ' +
226- 'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n' +
227- ' in Wrapper (at **)\n' +
228- ' in div (at **)\n' +
229- ' in Wrapper (at **)\n' +
230- ' in Component (at **)' ,
231- ] ) ;
232- } ) ;
233-
234122 it ( 'should not have string refs on unmounted components' , async ( ) => {
235123 class Parent extends React . Component {
236124 render ( ) {
0 commit comments