fix(tool-server): key Fabric component-tree measurement by nativeTag so tap coords don't collapse to 0.5,0.5#286
Draft
latekvo wants to merge 1 commit into
Draft
Conversation
…veTag debugger-component-tree returned every element with the same (0.5, 0.5) tap coordinate on the New Architecture (Fabric). The per-host measure cache keyed each host by 'f' + hostInfo.n, where on Fabric n is the shadow-node OBJECT — which stringifies to "f[object Object]" for every node. All hosts collapsed to a single cache entry, so every component was assigned the first (root) view's full-screen rect, rendering as a centre-of-screen tap for everything. Key by the numeric nativeTag (canonical.nativeTag) instead, with a WeakMap-by-identity fallback so distinct shadow nodes never share a key. Paper/old-arch is unchanged (its n was already a numeric tag). Verified live against a running RN 0.81 Fabric app: 2140 host nodes now produce 2140 distinct measure keys (was 1). Adds a script-level test (the existing component-tree test only covered the pure post-processor with pre-filled rects).
35eb73b to
dec89dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
debugger-component-treereturned every element with the same tap coordinate —(tap: 0.50,0.50)— on the New Architecture (Fabric/bridgeless), making the tool's primary output (per-element tap coordinates) unusable. Reproduced live on an RN 0.81.5 Fabric app; the tree walk, skip stats, and screen size were all correct, only the coordinates collapsed.Root cause
The injected script (
utils/debugger/scripts/component-tree.ts) batch-measures host views and caches each rect under a per-host key built as(hi.f ? 'f' : 'p') + hi.n. On Fabric,getHostInforeturns the shadow node object ashi.n({ f: true, n: fiber.stateNode.node }), so the key stringifies to"f[object Object]"for every host. All hosts collapsed to a single cache entry → only the first (root) view was measured → every component inherited the root's full-screen rect →(x + w/2)/screenW, (y + h/2)/screenH = 0.5, 0.5for all. Paper/old-arch was unaffected because therehi.nis already a numericnativeTag.Fix
Key the cache by a primitive
nativeTagon Fabric (fiber.stateNode.canonical.nativeTag, the same field the Paper branch already uses), with aWeakMap-by-identity fallback so distinct shadow nodes can never share a key even ifnativeTagwere ever absent.getHostInfonow carries an explicitkey, and the three cache-key derivations use it. Paper/old-arch behavior is unchanged.Testing
Live (first-hand), on a running RN 0.81 Fabric app — walking the live fiber tree:
'f' + node)"f[object Object]")'f' + nativeTag)Unit — adds
test/debugger/component-tree-script.test.ts, which evaluates the injected script against a mocked Fabric tree of three siblings at distinct positions (the existingcomponent-tree.test.tsonly covered the pure post-processor with pre-filled rects, which is why this shipped).vitest run→ passes with the fix; revertingcomponent-tree.tstomainfails it with{ y: 100 } to match { y: 300 }(the second component inheriting the first's rect — exactly the collapse).