Skip to content

#27: an SVG <text>, <image> and <title> keep their SVG attribute names - #35

Merged
shinyobjectz merged 2 commits into
shinyobjectz:mainfrom
JimGHTB12:svg-text-namespace
Nov 8, 2026
Merged

shinyobjectz merged 2 commits into
shinyobjectz:mainfrom
JimGHTB12:svg-text-namespace

Conversation

@JimGHTB12

@JimGHTB12 JimGHTB12 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

In a composition, an SVG <text> lost textAnchor and fontSize, and <image> and <title> lost their camelCase attributes the same way. Closes #27.

Why

in_svg leaves text, image and title out, because HTML has those tags too. For those three, sdk/ui's host says the namespace with $ns: "svg". The composition walk never did, so they became HTML elements, and textAnchor and fontSize were lowercased to attributes usvg doesn't know. On an update, systems/page/src/ops.rs decided SVG-ness by in_svg(kind) alone, so an animated fontSize was lowercased on every path, sdk/ui's included.

Change

  • runtime/page. The walk tracks whether it is inside an <svg>, and not back in HTML under a <foreignObject>, in IN_SVG beside IN_3D. BevyPage::sync resets it with the others. A text, image or title met there gets $ns: "svg", as sdk/ui's host gives it. The rule is two small functions in elements.rs, svg_inside and svg_owned.
  • systems/page/src/ops.rs. An update treats a node as SVG's when its element is in SVG's namespace, as well as when in_svg(kind) says so.

Testing

  • cargo test -p raea-runtime-page --lib -- svg_namespace passes, with two tests:
    • an_svg_texts_attributes_keep_their_svg_names_from_frame_to_frame takes a composition's path: the walk's Wants with the <text> carrying $ns, then Tree::diff, then ops::apply. Its second frame changes fontSize and textAnchor, so the diff sends only those. Without the ops.rs change it fails: the update adds fontsize="60" and textanchor="end" beside the stale font-size="48". It lives here, not in raea-sys-page, because that crate is at its 2,000-line limit.
    • text_image_and_title_are_svgs_only_inside_an_svg covers the scope rule: inside an <svg>, under a <foreignObject>, and an <svg> inside that <foreignObject>.
  • tools/size.sh passes on this branch merged with main, and layers.sh, names.sh, one-version.sh and no-void.sh pass on the branch.
  • Rendered on Windows 11 (Vulkan) with a dev build of this branch, measuring each line's black ink. The red guide line at x=320 doesn't count.

The repro from #27, camelCase, at x=320. This branch now draws exactly what kebab-case drew on canary.2:

canary.2 this branch
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

The animated case: one textAnchor="middle" line whose fontSize goes from 24 to 72 over 30 frames, rendered as a sequence so every frame after the first is an update:

Frame (fontSize) canary.2 this branch
0 (24) x 321 to 365, 11 px tall x 287 to 353, 17 px tall
15 (48) x 321 to 365, 11 px tall x 252 to 389, 35 px tall
29 (72) x 321 to 365, 11 px tall x 219 to 422, 52 px tall

On this branch every frame is centred on x=320, and the height follows fontSize.

Only Windows was run. <image> and <title> take the same rule and are covered by the unit tests, not by a render.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T01:17:37.536550Z 51f3c84 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@shinyobjectz shinyobjectz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @JimGHTB12. This is a careful fix with a clear write-up, and the before/after tables made it easy to follow.

I read through it, and the approach is right:

  • IN_SVG is set and restored around each subtree, and reset in sync with the others.
  • foreignObject switches back to HTML, and an <svg> inside it starts SVG again.
  • $ns: "svg" goes only on the three tags in_svg leaves out, matching what sdk/ui's host sends.
  • On update, ops.rs also accepts a node created in SVG's namespace, which fixes the animated fontSize for sdk/ui too.
  • The frame-to-frame test through Tree::diff and ops::apply is a good regression test, and moving it into raea-runtime-page was the right call.

One small change is needed before it can merge. It comes from main moving under you, not from your code. Two fixes landed today (22074b5 and 30960ed) and each added a line to raea-sys-page, which is now at exactly 2,000 lines on main. Merged onto main, this PR's ops.rs change (+2 −1) takes the crate to 2,001, so tools/size.sh refuses it. Could you rebase onto main and keep that hunk at net zero? For example, put the comment at the end of the line:

let svg = in_svg(kind) || m.element_name(n).is_some_and(|q| q.ns == ns!(svg)); // a text, image or title made in SVG's namespace (`$ns` at its create)

Once it's updated, I'll run the tests and #27's repro, including the animated fontSize case, on macOS and approve.

@shinyobjectz

Copy link
Copy Markdown
Owner

An update to my review, @JimGHTB12: please ignore what I said about shaving a line to fit raea-sys-page under its 2000-line limit. The crate reached that limit through our own landings today, so making room is our job, not yours. Sorry for the churn.

We're splitting the crate on our side. systems/page/src/ops.rs and ops/attrs.rs move unchanged into a new crate, raea-sys-page-ops (systems/page-ops/src/lib.rs and attrs.rs), and raea-sys-page re-exports it as ops, so raea_sys_page::ops::{Nodes, apply} in your test still works. You don't need to rebase or trim anything.

Your branch edits ops.rs, so it will show a conflict once the split is on main. You've allowed maintainer edits, so we'll rebase it ourselves, carrying your change into the moved file and keeping your commits and authorship. I'll test it after that and follow up here.

Thanks again for the fix, and for the clear write-up on #27.

shinyobjectz added a commit that referenced this pull request Nov 8, 2026
…tems/page-ops): ops.rs and ops/attrs.rs moved whole, with ALL_DAMAGE, which they mark damage with. raea-sys-page re-exports it as `ops` (and ALL_DAMAGE), so every raea_sys_page::ops path reads as before. raea-sys-page had reached 2000 lines through the day's landings, so a fix in it (PR #35, #37's next) had no room; it's 1424 now. No code changed: the moved tests pass (cargo test -p raea-sys-page-ops) and raea-sys-page checks with its tests.
JimGHTB12 and others added 2 commits November 7, 2026 18:15
…tribute names

The composition walk never said `$ns: "svg"` for the three SVG tags HTML also has, so inside an <svg> they became
HTML elements and their camelCase attributes were lowercased (textAnchor to textanchor, fontSize to fontsize), which
usvg doesn't know. The walk now tracks whether it is inside an <svg> and not back in HTML under a <foreignObject>
(IN_SVG, beside IN_3D), and gives those three `$ns: "svg"` there, as sdk/ui's host does. An update in ops.rs also
treats a node as SVG's when its element is in SVG's namespace, so an animated fontSize keeps `font-size` on every
frame, on sdk/ui's path too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ugh the frame diff

raea-sys-page is at its 2000-line limit (tools/size.sh), so the test of an SVG <text>'s attribute names leaves ops.rs.
In raea-runtime-page it takes the path a composition's frames take: the walk's Wants (the <text> with `$ns`), then
Tree::diff, whose second frame sends only the changed fontSize and textAnchor, then ops::apply. It fails without the
ops.rs change: the update adds fontsize and textanchor beside the stale font-size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@shinyobjectz shinyobjectz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Thank you, @JimGHTB12. Your diagnosis in #27 was exact, and the fix is just what you proposed.

Rebase. I rebased the branch onto main after our crate split (fd4d06c). Your two commits keep your authorship and their messages unchanged.

  • Your ops.rs change carried over by itself into systems/page-ops/src/lib.rs.
  • The only conflict was in elements.rs, where #28 had changed media_urls and its doc comment above your new functions. I kept both sides.

Checks

  • cargo test -p raea-runtime-page -p raea-sys-page-ops -p raea-sys-page passes.
  • Mutation check: with the namespace check in apply reverted, an_svg_texts_attributes_keep_their_svg_names_from_frame_to_frame fails, as it should.
  • Your repro, rendered on macOS (black ink's x extent and height):
before with this PR
Start 321 to 353, 12 px 322 to 420, 36 px
Middle 321 to 365, 12 px 253 to 388, 36 px
End 321 to 346, 12 px 238 to 316, 36 px

These match your kebab-case column.

  • Animated case: one <text> going from fontSize 24 with textAnchor="start" on frame 0 to 60 with "end" on frame 1, so frame 1's change arrives through the frame diff.
    • Before: both frames stuck at 12 px, starting at x=321.
    • With this PR: frame 0 is 322 to 389 (17 px), and frame 1 is 147 to 317 (44 px), ending left of the x=320 anchor.

A note, not a blocker. The frame-diff test writes $ns into its own input, so the page.insert("$ns", ...) line in the walk is covered only through svg_owned's logic. The renders above cover it end to end. A later test could go through the walk itself.

We'll merge it with a merge commit, so your commits show in history. Thanks again.

@shinyobjectz
shinyobjectz merged commit ea50176 into shinyobjectz:main Nov 8, 2026
4 checks passed
shinyobjectz added a commit that referenced this pull request Nov 8, 2026
…he walk (part of #27). It handed Tree::diff a frame written by hand with `$ns` already in it, so nothing tested the walk giving it: with elements.rs's `page.insert("$ns", "svg")` taken out, every test still passed. The test now builds the React tree a composition's commit leaves (a <text> in an <svg>, and a <title> under its <foreignObject>), walks it on each of two frames as BevyPage does, and sends the walk's wants through Tree::diff to ops::apply. It checks that the <text> has `$ns` and the HTML <title> doesn't, and that the second frame's fontSize and textAnchor keep their SVG names. With the insert taken out, it now fails at "the walk names the <text> SVG's". world.rs's walk (a plain App's page) now also starts from IN_3D 0 and IN_SVG false, as BevyPage's does.
shinyobjectz added a commit that referenced this pull request Nov 10, 2026
…ch shot its own <Camera3d>, switched with is_active; a cut is one render, its first frame drawn as a shot alone starts) and 3d/limits.md is regenerated from raea's guide (raea-skills #35, for RR2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG <text> ignores textAnchor and fontSize in compositions

2 participants