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

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.

0 reposts2 likes

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.

But I think I get why this isn’t accessible for screen readers. I’m definitely lacking the skill and knowledge when it comes to this whole topic; the do’s and don’ts.

On mac at least, you can check out the accessibility inspector since it works with the simulator. I'm definitely not an expert but I think the only way to make nested pressable actions available to accessibility tech would be to expose them as accessibilityActions on the outermost pressable.