Bug: jsx runtime doesn't apply defaultProps (breaks Recharts 2: "Could not find xAxis by id")
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- react, typescript
Rechercherichtung
Beginne in dist/react/jsx-runtime.js und vergleiche, wie jsx, jsxs und jsxDEV Props erstellen, mit der Behandlung von defaultProps in dist/react/element.js für createElement. Der Bericht enthält eine Reproduktion mit einer Klassenkomponente und einen Fehler in Recharts 2; bestätige, dass der Fix die übergebenen Props beibehält und nur undefinierte Werte ergänzt. Als abgeschlossen gilt die Arbeit, wenn die JSX-Runtime den Standardwert rendert und die gemeldete Achsenabfrage keine undefinierte ID mehr erhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
jsx() / jsxs() / jsxDEV() from @tanstack/redact/jsx-runtime don't apply a component's defaultProps. Redact's own createElement() does, and React 19's JSX runtime still does for class components, so libraries that rely on class defaultProps break when their consumers' JSX is compiled with the automatic runtime.
Reproduction
Any class component with defaultProps, rendered from JSX:
import { Component } from "react";
class Greeting extends Component<{ name?: string }> {
static defaultProps = { name: "world" };
render() {
return <p>Hello {this.props.name}</p>;
}
}
export const App = () => <Greeting />;
- React 19: renders
Hello world - Redact 0.2.0: renders
Hello(this.props.nameisundefined)
In the same app under Redact, createElement(Greeting) renders Hello world, so only the JSX runtime path is affected.
Real-world impact: Recharts 2
Recharts 2.x (2.15.4 here) declares its cartesian components as classes with defaultProps, e.g. XAxis.defaultProps = { xAxisId: 0, orientation: "bottom", … }. The chart reads XAxis.defaultProps itself when it registers axes (id 0), but the rendered <XAxis> receives no xAxisId, so this throws on any chart:
<BarChart data={data}>
<XAxis dataKey="day" />
<YAxis />
<Bar dataKey="value" />
</BarChart>
Invariant failed: Could not find xAxis by id "undefined" [undefined]. Available ids are: 0.
at invariant (recharts.js)
at useXAxisOrThrow (recharts.js)
at XAxisImpl (recharts.js)
at renderWithHooks (@tanstack/redact/dist/dom/dispatcher.js)
at renderFunction (@tanstack/redact/dist/dom/reconcile.js)
…
It's likely to affect other libraries too. For example react-remove-scroll (used by Radix Dialog, Sheet and DropdownMenu) sets RemoveScroll.defaultProps = { enabled: true, removeScrollBar: true, inert: false }, and Radix renders it through jsx(), so scroll locking is probably off under Redact. I haven't verified that one directly.
Likely cause
dist/react/jsx-runtime.js passes props through unchanged:
function jsx(type, props, key) {
return { $$typeof: REACT_ELEMENT_TYPE, type, key: key == null ? null : "" + key, ref: props?.ref ?? null, props };
}
while dist/react/element.js (createElement) merges type.defaultProps into props.
Suggested fix
Apply defaultProps in jsx / jsxDEV the same way createElement does (fill only keys that are undefined), copying props first since the compiled props object is shared:
const withDefaults = (type, props) => {
const dp = type?.defaultProps;
if (!dp) return props;
const out = { ...props };
for (const k in dp) if (out[k] === undefined) out[k] = dp[k];
return out;
};
React 19 only applies defaultProps for class components in the JSX runtime (function components warn), so matching that exactly would mean checking type.prototype?.isReactComponent. Applying it whenever defaultProps exists would also work for these cases.
Environment I used
@tanstack/redact0.2.0, defaultredact()preset- TanStack Start 1.169.4, Vite 8.3.5,
@cloudflare/vite-plugin1.65.0 react/react-dom19.2.0,recharts2.15.4- Reproduces in both dev and the production build
Quick summary
Redact's JSX runtime (jsx(), jsxs() and jsxDEV()) ignores a class component's defaultProps, unlike Redact's own createElement() and React 19, so renders Hello instead of Hello world. It has crashed every Recharts 2 chart with a "Could not find xAxis by id "undefined", likely breaks Radix's scroll lock too, and the issue suggests a few lines in jsx() to fill in defaultProps the way createElement() already does.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 408
- Forks
- 13
- Ø Merge
- 1 Std. 22 Min.
- Gemergte PRs (30 T.)
- 16
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/redact
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
TanStack/redact#67 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 50/100
TanStack/redact#87 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in TanStack/redact
Ähnliche Issues
-
New icon: `filter-clear`Offencalcite-ui-icons enhancement impact - p3 - not time sensitive needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
Esri/calcite-design-system#15467 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
diegosouzapw/OmniRoute#18390 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 86/100
guilhermerodz/input-otp#157 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
davidjerleke/embla-carousel#1414 ·
Maintainer antworten meist innerhalb von 4 Tagen