Skip to content

SVG <text> ignores textAnchor and fontSize in compositions #27

Closed

Description

@JimGHTB12

In a composition, <text textAnchor="middle" fontSize={48}> inside an <svg> draws at about 16 px, starting at x. The same attributes written in kebab-case work, so the SVG renderer is fine. The names are lowercased on the way in.

Repro

import { AbsoluteFill, Composition, registerRoot } from "raea";
// three SVG <text> lines at x=320, anchored start, middle and end, at 48 px; a red line marks x=320
function Clip() {
  return (
    <AbsoluteFill style={{ background: "#ffffff" }}>
      <svg width={640} height={360} viewBox="0 0 640 360">
        <line x1={320} y1={0} x2={320} y2={360} stroke="#ff0000" strokeWidth={2} />
        <text x={320} y={90} fontSize={48} textAnchor="start" fill="#000000">Start</text>
        <text x={320} y={190} fontSize={48} textAnchor="middle" fill="#000000">Middle</text>
        <text x={320} y={290} fontSize={48} textAnchor="end" fill="#000000">End</text>
      </svg>
    </AbsoluteFill>
  );
}
registerRoot(() => <Composition id="t" component={Clip} width={640} height={360} fps={30} durationInFrames={1} />);

raea render edit.tsx --frame 0 -o a.png on raea 0.1.0-canary.2 on Windows 11. The table gives the black ink's horizontal extent and height:

camelCase (textAnchor, fontSize) kebab-case (text-anchor, font-size)
Start x 321 to 352, 11 px tall x 322 to 420, 35 px tall
Middle x 321 to 365, 11 px tall x 253 to 388, 34 px tall
End x 321 to 346, 11 px tall x 238 to 315, 34 px tall

Why, from reading main (cc729f2)

  • in_svg (systems/page/src/ops/attrs.rs:6-16) leaves out text, image and title on purpose, because those names also exist in HTML. For them the namespace must come from a $ns: "svg" prop.
  • Only sdk/ui's reconciler sets $ns. A composition's page walk (runtime/page/src/elements.rs:137, :148) doesn't track whether it is inside an <svg>. So <text> becomes an HTML-namespace element, and its attributes are lowercased to textanchor and fontsize, which usvg doesn't know.
  • sdk/ui/parity/cases/p15-media/svg-text.tsx tests exactly these attributes, but it runs through sdk/ui's path, which sets $ns. That's why parity passes.
  • On an update, systems/page/src/ops.rs:232 uses in_svg(kind) without looking at the node's namespace. So an animated fontSize on an SVG <text> is lowercased on every path, sdk/ui included.

Suggested fix

Track "inside an <svg>, not back in HTML under a <foreignObject>" during the walk, next to IN_3D in runtime/page/src/walk.rs, and set $ns: "svg" on text, image and title there. In ops.rs:232, also treat a node as SVG when its element is in the SVG namespace. That's about 15 lines. I'm happy to send it as a PR, with this repro and an animated fontSize case.

Activity

  1. shinyobjectz commented on Nov 7, 2026

    @shinyobjectz
    Owner

    Thanks for the careful write-up and the measurements. The diagnosis is right: the composition walk in runtime/page never sets $ns: "svg", so text, image and title inside an <svg> become HTML elements and their attributes are lowercased. Creating a node honours $ns (systems/page/src/ops.rs:146), but the update at ops.rs:232 only looks at in_svg(kind), so an animated fontSize is lowercased on every path.

    Yes please to the PR, with your repro and the animated fontSize case. Tracking "inside an <svg>, not under a <foreignObject>" beside IN_3D in walk.rs is the shape we'd want too. We'll review it when it's up.

  2. added a commit that references this issue on Nov 8, 2026
  3. added 2 commits that reference this issue on Nov 8, 2026
  4. shinyobjectz commented on Nov 8, 2026

    @shinyobjectz
    Owner

    Merged as ea50176 with your two commits in history. Thanks for the diagnosis and the fix, and sorry for the rebase churn: the crate limit we hit was our own doing that day. The fix is in from the next canary.

  5. added a commit that references this issue on Nov 8, 2026
  6. shinyobjectz commented on Nov 8, 2026

    @shinyobjectz
    Owner

    A follow-up to #35: 0032757 makes the regression test take its frames from the composition walk itself. Before, it gave the frame diff a hand-written frame with $ns already in it, so taking the walk's $ns insert out left every test passing. Now the test builds the React tree a composition leaves (a <text> in an <svg>, and a <title> under a <foreignObject>) and walks it on two frames. It checks that the <text> gets $ns, that the HTML <title> doesn't, and that an animated fontSize/textAnchor keeps its SVG names. Without the insert it fails. No render path changed, so there's no fps difference to report.

    Thanks again for the report and the fix, @JimGHTB12.

  7. added a commit that references this issue on Nov 8, 2026
    ea50176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions