Post

I was exploring a hard to debug memory leak in react native for at least 6 hours today. Turns out that when you don't add accessibilityLabel to RectButton or Pressable, it will fucking traverse all children to find a Text node or View with accessibilityLabel. This is insane. 1/4

4 reposts36 likes

I honestly never even thought about accessibility. We even use the NativeView and NativeText components directly to optimize performance by skipping all of that. We iterate so fast in startups, there’s no room for it until we have PMF.

> I honestly never even thought about accessibility. Probably why they did there best to make it accessible by default

Is this an actual memory leak? From the code samples, it looks like it should pile up some memory but then let that go. I agree this isn't a good default, and perhaps a dev-only warning saying "need an accessibility label on <view name>" would be best.

From 300MB to 7GB plus a full hang is even worse. Yeah, it’s not a leak, but an infinite traversal bug. In some very rare and not reliably reproducible cases, nested touchables can trigger this bug and completely freeze the app in our case. Adding a fallback `accessibilityLabel` did the trick.

Generally speaking, I don’t like these automated and expensive lookups. I’d rather have a dev-only warning that forces users to handle accessibility manually. And lookups should bail out fast and have some railguards.

Our FeedItem is actually a GestureDetector (handles play/pause and double-tap to like), and the RectButtons are placed on top of it—not even nested in the tree. We do have nested pressables, eg in lists where the whole item opens a sheet, but the avatar inside navigates to the profile instead.

I added a simple "fuck off" as Label and the rare bug is gone. This is just madness and a really bad default by RNGH and React Native. 2/4

Imagine, that change made our app the snappiest and fastest react native app I've ever seen. The fucking FPS counter is finally going up, not down when tapping a button. :D

Hah, been there. My version was a useCallback with a 10-item dependency array that changed every tick. Deleted it, app went from slideshow to butter. Sometimes the nuclear "fuck off" fix is the only right one.