camelCase SVG attributes (patternUnits, ...) are lowercased, causing silent hydration re-render and broken patterns
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- frontend
Direzione di ricerca
Start in packages/redact/src/core/attributes.ts at attributeName(), where SVG names fall through to toLowerCase(), then check validateHydrationProps and the client setAttribute path, which must use the same mapping. Run the issue's jsdom repro and add a test that hydrates an SVG pattern with patternUnits. Done when the SVG casing is preserved, hydration reports no mismatch, and the server nodes are kept.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Env: @tanstack/[email protected], TanStack Start (prerendered), Chromium 154. Same code on main (packages/redact/src/core/attributes.ts).
camelCase SVG attributes are lowercased, so hydration silently re-renders the boundary
Where: attributeName() in dist/core/attributes.js (L7–19). For SVG it only kebab-cases names matching /^(?:clip|fill|stroke)/, special-cases viewBox, and falls through to name.toLowerCase() for everything else. Case-sensitive SVG attributes such as patternUnits, patternTransform, gradientUnits, gradientTransform, preserveAspectRatio, stdDeviation, markerWidth, refX etc. are therefore emitted as patternunits, patterntransform, ...
This breaks two things:
- Hydration mismatch. The browser's HTML parser fixes the case of known SVG attributes inside
<svg>(patternunits→patternUnits), butvalidateHydrationPropslooks upgetAttribute("patternunits"), which is case-sensitive on SVG elements and returnsnull. Hydration aborts and the enclosing Suspense boundary is client-rendered. Under TanStack Start that boundary is the route's<main>, so the whole page body is thrown away and rebuilt on every load, with nothing logged unlessonRecoverableErroris passed. - Wrong rendering on the client. The rebuilt element gets the lowercase attribute via
setAttribute, which SVG does not recognise.pattern.patternUnits.baseValis2(objectBoundingBox) instead of1(userSpaceOnUse), so the pattern does not render. React renders it correctly.
Side effects we measured in a real app: loading="lazy" images inside the rebuilt subtree load eagerly, the LCP element is replaced after hydration (Lighthouse observed LCP moves from FCP to after hydration), and the re-render adds to the long hydration task.
Repro (jsdom/vitest, also reproduced in Chromium):
import { createElement as h } from '@tanstack/redact';
import { renderToString } from '@tanstack/redact/server';
import { hydrateRoot } from '@tanstack/redact/dom-client';
import { flushSync } from '@tanstack/redact/dom';
const App = () =>
h('div', null,
h('svg', null,
h('defs', null,
h('pattern', { id: 'p', width: '10', height: '10',
patternUnits: 'userSpaceOnUse', patternTransform: 'rotate(45)' })),
h('rect', { fill: 'url(#p)' })));
const html = renderToString(h(App));
const c = document.createElement('div');
c.innerHTML = html;
document.body.append(c);
const before = c.firstChild;
flushSync(() => {
hydrateRoot(c, h(App), { onRecoverableError: (e) => console.warn(String(e)) });
});
console.log(html, c.firstChild === before);
<div><svg><defs><pattern id="p" width="10" height="10" patternunits="userSpaceOnUse" patterntransform="rotate(45)"></pattern></defs><rect fill="url(#p)"></rect></svg></div>
Error: Hydration attribute mismatch on <pattern> for "patternunits": expected "userSpaceOnUse" but found nothing.
false
With react-dom the same component serializes patternUnits="userSpaceOnUse", hydrates without errors and keeps the server nodes.
Workaround: render the <pattern> markup through dangerouslySetInnerHTML on <defs> so the SVG parser handles the casing.
Suggested fix: in the SVG namespace, keep the prop name as written and only map a known list to kebab-case (strokeWidth → stroke-width, fontSize → font-size, ...), which is how react-dom behaves. Lowercasing should only apply to HTML elements. Sharing the same mapping between SSR, client setAttribute and validateHydrationProps would keep the three in sync.
- Lingua principale
- TypeScript
- Stelle
- 640
- Fork
- 32
- Merge medio
- 1h 15m
- PR unite (30g)
- 7
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 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TanStack/redact#195 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/redact#142 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/redact
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno