From c3a1d23cc846ec468c90d75ce74667cebab68761 Mon Sep 17 00:00:00 2001 From: Adeel Ejaz Date: Mon, 23 Nov 2026 19:17:49 +0000 Subject: [PATCH] [DO NOT MERGE] RNTester reproducer for #60244 --- .../examples/Playground/RNTesterPlayground.js | 93 ++++++++++++++++++- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js b/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js index 8e6b10479de7..c69312f72d84 100644 --- a/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js +++ b/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js @@ -12,22 +12,109 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import RNTesterText from '../../components/RNTesterText'; import * as React from 'react'; -import {StyleSheet, View} from 'react-native'; +import {useEffect, useLayoutEffect, useState} from 'react'; +import {Button, StyleSheet, Text, View} from 'react-native'; -function Playground() { +// Reproducer for a data race in RCTComponentViewFactory (iOS, Fabric): +// registering a component name the factory has never seen (the +// UnimplementedView / legacy interop fallbacks of _registerComponentIfPossible:) +// writes the factory's maps without its lock on the JS thread, while the main +// thread reads them in createComponentViewWithComponentHandle:. +// +// Each frame on which a large Text batch commits (more views than the 1024-view +// recycle pool, so the main thread creates new ones), detached shadow nodes are +// created under fresh names right after the commit. Each fresh name forces a +// fallback registration while the main thread is still mounting the batch. +// +// With ThreadSanitizer on RCTComponentViewFactory.mm this reports a data race +// within seconds. Without it, Debug builds intermittently abort with +// "ComponentView with componentHandle ... (Paragraph) not found". + +const FRAMES = 240; +const NAMES_PER_FRAME = 3000; +const TEXTS = 1500; + +let nextName = 0; + +function registerFreshNames(count: number): void { + // $FlowFixMe[cannot-resolve-name] Fabric's JSI binding + const fabric = global.nativeFabricUIManager; + if (fabric == null) { + throw new Error('This reproducer needs the New Architecture (Fabric)'); + } + for (let i = 0; i < count; i++) { + const n = nextName++; + fabric.createNode(2_000_000_000 + n * 2, `ReproProbe${n}`, 1, {}, {}); + } +} + +function Stress(): React.Node { + const [frame, setFrame] = useState(0); + const done = frame >= FRAMES; + + useLayoutEffect(() => { + if (!done && frame % 2 === 0) { + registerFreshNames(NAMES_PER_FRAME); + } + }, [frame, done]); + + useEffect(() => { + if (done) { + return; + } + const id = requestAnimationFrame(() => setFrame(f => f + 1)); + return () => cancelAnimationFrame(id); + }, [frame, done]); + + if (done) { + return Done: no crash; + } + return ( + + {frame % 2 === 0 + ? Array.from({length: TEXTS}, (_, i) => ( + + Probe + + )) + : null} + + ); +} + +function Playground(): React.Node { + const [running, setRunning] = useState(false); return ( - Edit "RNTesterPlayground.js" to change this file + RCTComponentViewFactory registration race (iOS, Fabric). Build with + ThreadSanitizer on RCTComponentViewFactory.mm, then press Start. + {running ? ( + + ) : ( +