Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Bug: jsx runtime doesn't apply defaultProps (breaks Recharts 2: "Could not find xAxis by id")

Offen Anfängerfreundlich
#58 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

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
Bereich
backend, frontend

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.name is undefined)

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/redact 0.2.0, default redact() preset
  • TanStack Start 1.169.4, Vite 8.3.5, @cloudflare/vite-plugin 1.65.0
  • react / react-dom 19.2.0, recharts 2.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

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/redact

Alle Issues in TanStack/redact

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.