fix(profiler): keep all same-named components and surface platform variants#368
Draft
latekvo wants to merge 1 commit into
Draft
fix(profiler): keep all same-named components and surface platform variants#368latekvo wants to merge 1 commit into
latekvo wants to merge 1 commit into
Conversation
…riants The AST component index is keyed by name, and on a collision (e.g. List in List.tsx and List.web.tsx) it kept whichever file the directory walk reached first and discarded the rest. A lookup for that name could then return the wrong platform variant's source, with no signal that other matches existed. Collect every match per name, choose a deterministic primary — base files preferred over .web/.ios/.android/.native variants, then by path/line/col so the result no longer depends on walk order — and expose the remaining matches as otherMatches on the entry. react-profiler-component-source now returns otherMatches alongside the primary so callers can disambiguate.
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
The AST component index (
buildAstIndexWithDiagnostics) is keyed by component name. When two files define a component with the same name — most commonly platform variants, e.g.ListinList.tsxandListinList.web.tsx— the index kept whichever file the directory walk happened to reach first (if (!index.has(name))) and threw the rest away.So a lookup for
Listcould return the wrong platform variant's source, with no signal that other matches even existed. And because it depended on filesystem walk order, whichListsurvived was effectively arbitrary.Raised in review on #287.
Fix
.web/.ios/.android/.nativevariants (those only override the base when bundling for that platform), then ties break on path → line → column. The result no longer depends on directory-walk order.otherMatcheson the index entry.react-profiler-component-sourcenow returnsotherMatches: [{ file, line, col }]alongside the primary, so a caller asking forListcan tell the locations apart instead of trusting a single arbitrary file.react-profiler-analyzeneeds no change — it enriches findings with the (now deterministic) primary location, which is strictly better than before; surfacing per-finding alternates there is out of scope.Tests
packages/tool-server/test/react-profiler/ast-index.test.ts(index layer) and a newcomponent-source-duplicates.test.ts(end-to-end through the tool'sexecute):List.tsx+List.web.tsx→ primary is the base file, its source is returned,List.web.tsxis underotherMatches;.android+.ios, no base) → deterministic primary by path;otherMatches.The two collision assertions fail on pre-fix code (no
otherMatches, arbitrary primary) and pass with the fix. Verified locally with Node 20:vitest run test/react-profiler/— 80 passed;tsc --buildclean; prettier + eslint clean.