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(
224224 }
225225 }
226226 }
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+ }
227259 return mixedRef ;
228260}
229261
Original file line number Diff line number Diff line change @@ -224,6 +224,39 @@ function coerceRef(
224224 }
225225 }
226226 }
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+
227260 return mixedRef ;
228261}
229262
Original file line number Diff line number Diff line change 77
88import ReactNoopUpdateQueue from './ReactNoopUpdateQueue' ;
99import assign from 'shared/assign' ;
10- import { warnAboutStringRefs } from 'shared/ReactFeatureFlags' ;
1110
1211const 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__ ) {
1813 Object . freeze ( emptyObject ) ;
1914}
2015
You can’t perform that action at this time.
0 commit comments