react-doctor/duplicate-jsx-subtree
Substantial JSX structure repeats across distinct React composition roots and may belong in a shared component
- Status
- Active
- Category
- Maintainability
- Assessment
- Evidence-required risk
- Required evidence
- source code, repository context, product intent
- Default configuration
- Enabled
- Default severity
- warn
Show technical metadata
- Scope
- All supported frameworks
- Active when
- React projects
- Priority
- 52 (P2)
- Source
- react-doctor-core
- Rule set
- oxlint-plugin-react-doctor 0.9.3 (prompt schema 2)
- Documentation
- Official documentation
On this page
Validation prompt
Confirm the detector match and collect the required evidence before deciding whether an edit is warranted.
This project-level check fingerprints JSX trees with at least 6 nodes and depth 3, groups structurally equivalent trees across distinct component roots, and reports maximal families with at least two occurrences. It normalizes data leaves while preserving component names, expression structure, member paths, and operators. Confirm the copies represent the same UI concept and would benefit from one interface. Reject when the resemblance is incidental, the variants are likely to evolve independently, or extraction would require a broad prop surface. Use the related locations and lexical composition paths to inspect every copy before deciding.
Evidence boundary
The diagnostic proves only that the detector’s modeled source pattern matched. It does not prove runtime impact, product intent, rendered failure, or that one remediation is correct.
Establish the environment, repository policy, exceptions, and required rendered or runtime evidence before deciding the occurrence.
Record one outcome:
- Confirmed failure: The required evidence establishes the violation.
- Rejected: A documented exception or false-positive predicate applies.
- Needs evidence: Named evidence can still be collected.
- Unavailable: Required evidence cannot be collected in this run.
- Waived with evidence: An authorized, scoped exception applies to an established failure.
- Observation: The review records an optional tradeoff without claiming a defect.
A waiver records its scope, authority, evidence, and review condition. It is not a pass or false positive.
Default severity is registry metadata. Use the occurrence’s JSON severity after repository configuration when ordering real findings.
Review a candidate correction
Apply this candidate correction only after the required evidence confirms the risk.
Reported pattern
const RevenueCard = () => (
<section>
<header><ChartIcon /><h2>Revenue</h2></header>
<strong>$42k</strong>
<small>Updated now</small>
</section>
);
const OrdersCard = () => (
<section>
<header><ChartIcon /><h2>Orders</h2></header>
<strong>128</strong>
<small>Updated now</small>
</section>
);Candidate corrected pattern
const MetricCard = ({ title, value }: MetricCardProps) => (
<section>
<header><ChartIcon /><h2>{title}</h2></header>
<strong>{value}</strong>
<small>Updated now</small>
</section>
);
const Dashboard = () => (
<>
<MetricCard title="Revenue" value="$42k" />
<MetricCard title="Orders" value="128" />
</>
);Fix prompt
Apply this candidate correction only after the required evidence confirms the risk.
Extract one shared component only after confirming the copies represent the same UI concept. Choose props for meaningful data or behavior differences, keep composition points explicit, and replace every reported copy without changing rendering, event behavior, semantics, or accessibility. Re-run React Doctor across the project to confirm the duplicate family is gone and no new diagnostics were introduced.
Repository-wide copy prompt
Use this repository-wide prompt only after validating each occurrence. For one occurrence, use the guidance above.
Show repository-wide prompt
Fix every confirmed react-doctor/duplicate-jsx-subtree diagnostic in the current repository.
Required change:
- Extract one shared component only after confirming the copies represent the same UI concept. Choose props for meaningful data or behavior differences, keep composition points explicit, and replace every reported copy without changing rendering, event behavior, semantics, or accessibility. Re-run React Doctor across the project to confirm the duplicate family is gone and no new diagnostics were introduced.
Validation before editing:
This project-level check fingerprints JSX trees with at least 6 nodes and depth 3, groups structurally equivalent trees across distinct component roots, and reports maximal families with at least two occurrences. It normalizes data leaves while preserving component names, expression structure, member paths, and operators. Confirm the copies represent the same UI concept and would benefit from one interface. Reject when the resemblance is incidental, the variants are likely to evolve independently, or extraction would require a broad prop surface. Use the related locations and lexical composition paths to inspect every copy before deciding.
Constraints:
- Confirm every occurrence independently.
- Make the smallest change that addresses the root cause.
- Preserve unrelated behavior, interfaces, content, and semantics.
- Reuse existing project conventions and components.
- Do not suppress the rule merely to clear the report.
Assessment:
- Record detector evidence, applicability, missing evidence, and one outcome: Confirmed failure, Rejected, Needs evidence, Unavailable, Waived with evidence, or Observation.
Verification:
- Run focused tests and every repository-mandated check.
- Run React Doctor and confirm the diagnostic no longer appears from changed code.
- Run an unfiltered scan of the affected scope before claiming no cross-category regression.
- Report checks that were not run instead of claiming they passed.