React Native "testID" View prop


(Andrew Goodale) #1

A note attached to the doc on the testID prop for View says:
“This disables the ‘layout-only view removal’ optimization for this view!”

I searched for more information about what “layout-only view removal” is, and it looks like that feature was removed from react-native last year. Is this statement still relevant? Are there downsides to setting this prop? I was going to start using it on some components to help with locating the view in the Xcode view hierarchy debugger.


(Adam Mackintosh) #2

I have the same question after reading that same line in the docs. It is a one sentence assertion without supplied reasoning why we care about that.

To put exactness to it, I might like to know if there is a recommended strategy for handling dev vs. prod environments, for example setting it to false on prod.

It would be nice to know what aspects of the app are affected by ‘layout-only view removal’.

With that said, I am inclined to ensure it is turned off in prod because view, layout, and stack navigator memory usage and performance concerns are paramount for maximizing UX quality. It sounds like garbage collection and memoization/caching are related to this. By that I mean something recycling or purge related.

It means you probably wouldn’t see the aspects of the app that testID has bearing on unless you had perhaps many views open, or complex layout, or lots of views in the stack navigator cranking up your memory usage, basically pissing into the JavaScript heap and then overworking the CPU because a reference was maintained in a parent closure when otherwise it would have been garbage collected if testID was falsy.

I honestly have no idea, but I might as well put some ideas out there. Someone should update the docs with an additional blob of text about it.