You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on:
- #28464
---
This moves the entire string ref implementation out Fiber and into the
JSX runtime. The string is converted to a callback ref during element
creation. This is a subtle change in behavior, because it will have
already been converted to a callback ref if you access element.prop.ref
or element.ref. But this is only for Meta, because string refs are
disabled entirely in open source. And if it leads to an issue in
practice, the solution is to switch to a different ref type, which Meta
is going to do regardless.
'Warning: Component "div" contains the string ref "inner". '+
171
+
'Warning: Component "Component" contains the string ref "inner". '+
173
172
'Support for string refs will be removed in a future major release. '+
174
173
'We recommend using useRef() or createRef() instead. '+
175
174
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
175
+
' in Wrapper (at **)\n'+
176
176
' in div (at **)\n'+
177
177
' in Wrapper (at **)\n'+
178
178
' in Component (at **)',
179
-
'Warning: Component "Component" contains the string ref "outer". '+
180
-
'Support for string refs will be removed in a future major release. '+
181
-
'We recommend using useRef() or createRef() instead. '+
182
-
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
'Support for string refs will be removed in a future major release. '+
101
101
'We recommend using useRef() or createRef() instead. '+
102
102
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
'Warning: Component "div" contains the string ref "resetDiv". '+
133
-
'Support for string refs will be removed in a future major release. '+
134
-
'We recommend using useRef() or createRef() instead. '+
135
-
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
136
-
' in div (at **)\n'+
137
-
' in TestRefsComponent (at **)',
138
-
'Warning: Component "span" contains the string ref "clickLog0". '+
139
-
'Support for string refs will be removed in a future major release. '+
140
-
'We recommend using useRef() or createRef() instead. '+
141
-
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
142
-
' in span (at **)\n'+
143
-
' in ClickCounter (at **)\n'+
132
+
'Warning: Component "TestRefsComponent" contains the string '+
133
+
'ref "resetDiv". Support for string refs will be removed in a '+
134
+
'future major release. We recommend using useRef() or createRef() '+
'Support for string refs will be removed in a future major release. '+
353
353
'We recommend using useRef() or createRef() instead. '+
354
354
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
355
+
' in div (at **)\n'+
355
356
' in A (at **)',
356
357
]);
357
358
expect(a.refs[1].nodeName).toBe('DIV');
358
359
});
359
360
360
-
// @gate !disableStringRefs
361
361
it('provides an error for invalid refs',async()=>{
362
362
constcontainer=document.createElement('div');
363
363
constroot=ReactDOMClient.createRoot(container);
364
364
awaitexpect(async()=>{
365
365
awaitact(()=>{
366
366
root.render(<divref={10}/>);
367
367
});
368
-
}).rejects.toThrow(
369
-
'Element ref was specified as a string (10) but no owner was set.',
370
-
);
368
+
// TODO: This throws an AggregateError. Need to update test infra to
369
+
// support matching against AggregateError.
370
+
}).rejects.toThrow();
371
371
awaitexpect(async()=>{
372
372
awaitact(()=>{
373
373
root.render(<divref={true}/>);
374
374
});
375
-
}).rejects.toThrow(
376
-
'Element ref was specified as a string (true) but no owner was set.',
377
-
);
375
+
// TODO: This throws an AggregateError. Need to update test infra to
376
+
// support matching against AggregateError.
377
+
}).rejects.toThrow();
378
378
awaitexpect(async()=>{
379
379
awaitact(()=>{
380
380
root.render(<divref={Symbol('foo')}/>);
@@ -520,14 +520,10 @@ describe('creating element with string ref in constructor', () => {
520
520
awaitact(()=>{
521
521
root.render(<RefTest/>);
522
522
});
523
-
}).rejects.toThrowError(
524
-
'Element ref was specified as a string (p) but no owner was set. This could happen for one of'+
525
-
' the following reasons:\n'+
526
-
'1. You may be adding a ref to a function component\n'+
527
-
"2. You may be adding a ref to a component that was not created inside a component's render method\n"+
528
-
'3. You have multiple copies of React loaded\n'+
529
-
'See https://react.dev/link/refs-must-have-owner for more information.',
530
-
);
523
+
})
524
+
// TODO: This throws an AggregateError. Need to update test infra to
'Warning: Component "Indirection" contains the string ref "child1". '+
580
+
'Warning: Component "Parent" contains the string ref "child1". '+
585
581
'Support for string refs will be removed in a future major release. '+
586
582
'We recommend using useRef() or createRef() instead. '+
587
583
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref\n'+
'Warning: Component "Root" contains the string ref "child2". '+
604
-
'Support for string refs will be removed in a future major release. '+
605
-
'We recommend using useRef() or createRef() instead. '+
606
-
'Learn more about using refs safely here: https://react.dev/link/strict-mode-string-ref',
0 commit comments