Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#58 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
backend, frontend

Direzione di ricerca

Inizia da dist/react/jsx-runtime.js e confronta il modo in cui jsx, jsxs e jsxDEV costruiscono le props con la gestione di defaultProps in dist/react/element.js per createElement. Il report include una riproduzione con un componente di classe e un errore in Recharts 2; conferma che la correzione conserva le props fornite e completa solo i valori indefiniti. Il lavoro è completato quando il runtime JSX esegue il rendering del valore predefinito e la ricerca dell’asse segnalata non riceve più un id indefinito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
408
Fork
13
Merge medio
1h 22m
PR unite (30g)
16

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/redact

Tutte le issue di TanStack/redact

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.