Bug: jsx runtime doesn't apply defaultProps (breaks Recharts 2: "Could not find xAxis by id")
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
Línea de trabajo
Empieza en dist/react/jsx-runtime.js y compara cómo jsx, jsxs y jsxDEV construyen las props con el tratamiento de defaultProps en dist/react/element.js para createElement. El informe incluye una reproducción con un componente de clase y un fallo en Recharts 2; confirma que la corrección conserva las props proporcionadas y solo completa los valores indefinidos. Se considera terminado cuando el runtime de JSX renderiza el valor predeterminado y la búsqueda del eje reportada deja de recibir un id indefinido.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 408
- Forks
- 13
- Merge medio
- 1 h 44 min
- PR fusionados (30 d)
- 21
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/redact
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
TanStack/redact#67 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/redact
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
scaleway/ultraviolet#7089 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
tencent-connect/dsh-qqbot#81 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Pen taps on sidebar rows start a drag and lose their clickPosiblemente ocupada @makhnatkin la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
clangd/vscode-clangd#1009 ·