File tree Expand file tree Collapse file tree 3 files changed +66
-6
lines changed Expand file tree Collapse file tree 3 files changed +66
-6
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,38 @@ function coerceRef(
224
224
}
225
225
}
226
226
}
227
+
228
+ if ( typeof mixedRef === 'function' && element . _owner ) {
229
+ const owner : ?Fiber = ( element . _owner : any ) ;
230
+ if ( owner ) {
231
+ const ownerFiber = ( ( owner : any ) : Fiber ) ;
232
+
233
+ if ( ownerFiber . tag === ClassComponent ) {
234
+ const functionRef = mixedRef ;
235
+ const resolvedInst = ownerFiber . stateNode ;
236
+
237
+ // Check if previous function ref matches new function ref
238
+ if (
239
+ current !== null &&
240
+ current . ref !== null &&
241
+ typeof current . ref === 'function' &&
242
+ current . ref . _functionRef === functionRef
243
+ ) {
244
+ return current . ref ;
245
+ }
246
+
247
+ const ref = function ( value ) {
248
+ if ( resolvedInst . refs === emptyRefsObject ) {
249
+ // This is a lazy pooled frozen object, so we need to initialize.
250
+ resolvedInst . refs = { } ;
251
+ }
252
+ functionRef . call ( resolvedInst , value ) ;
253
+ } ;
254
+ ref . _functionRef = functionRef ;
255
+ return ref ;
256
+ }
257
+ }
258
+ }
227
259
return mixedRef ;
228
260
}
229
261
Original file line number Diff line number Diff line change @@ -224,6 +224,39 @@ function coerceRef(
224
224
}
225
225
}
226
226
}
227
+
228
+ if ( typeof mixedRef === 'function' && element . _owner ) {
229
+ const owner : ?Fiber = ( element . _owner : any ) ;
230
+ if ( owner ) {
231
+ const ownerFiber = ( ( owner : any ) : Fiber ) ;
232
+
233
+ if ( ownerFiber . tag === ClassComponent ) {
234
+ const functionRef = mixedRef ;
235
+ const resolvedInst = ownerFiber . stateNode ;
236
+
237
+ // Check if previous function ref matches new function ref
238
+ if (
239
+ current !== null &&
240
+ current . ref !== null &&
241
+ typeof current . ref === 'function' &&
242
+ current . ref . _functionRef === functionRef
243
+ ) {
244
+ return current . ref ;
245
+ }
246
+
247
+ const ref = function ( value ) {
248
+ if ( resolvedInst . refs === emptyRefsObject ) {
249
+ // This is a lazy pooled frozen object, so we need to initialize.
250
+ resolvedInst . refs = { } ;
251
+ }
252
+ functionRef . call ( resolvedInst , value ) ;
253
+ } ;
254
+ ref . _functionRef = functionRef ;
255
+ return ref ;
256
+ }
257
+ }
258
+ }
259
+
227
260
return mixedRef ;
228
261
}
229
262
Original file line number Diff line number Diff line change 7
7
8
8
import ReactNoopUpdateQueue from './ReactNoopUpdateQueue' ;
9
9
import assign from 'shared/assign' ;
10
- import { warnAboutStringRefs } from 'shared/ReactFeatureFlags' ;
11
10
12
11
const emptyObject = { } ;
13
- if (
14
- __DEV__ &&
15
- // For string refs we recommend the `string-refs` codemod that requires unsealed `this.refs`
16
- ! warnAboutStringRefs
17
- ) {
12
+ if ( __DEV__ ) {
18
13
Object . freeze ( emptyObject ) ;
19
14
}
20
15
You can’t perform that action at this time.
0 commit comments