Bug: jsx runtime doesn't apply defaultProps (breaks Recharts 2: "Could not find xAxis by id")
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
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.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.
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/redact
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
TanStack/redact#67 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
TanStack/redact#87 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/redact
Issue simili
-
[Bug]: Payment providers removed from config are never disabled in payment_providerForse già presa @medusa-os-bot l’ha presa oggi. Apertatype: bug
Difficoltà 2/5 Mezza giornata Idoneità per principianti 82/100
medusajs/medusa#17544 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
software-mansion/argent#1651 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
lane:reliability
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno