Refactor SVG/MathML namespace handling#55
Conversation
Introduce a scope for managing XML namespaces. This allows for proper handling of SVG and MathML elements within nested structures, including reactive branches and teleported content. This change also improves the `createContainer` logic by inheriting namespaces from parent scopes and setting them explicitly when needed, rather than relying on string manipulation or re-serialization.
Review Summary by QodoRefactor SVG/MathML namespace handling with scope-based inheritance
WalkthroughsDescription• Introduce namespace scope management for SVG/MathML elements • Replace string serialization workaround with scope-based namespace inheritance • Wrap child components with NamespaceScope.Provider to preserve namespaces • Handle foreignObject namespace switching back to HTML • Add comprehensive test coverage for namespace preservation Diagramflowchart LR
A["createContainer"] -->|"reads inherited namespace"| B["NamespaceScope.Provider"]
B -->|"wraps children"| C["SVG/MathML elements"]
C -->|"preserve namespace"| D["Nested components"]
E["foreignObject"] -->|"switches to HTML"| F["HTML descendants"]
G["Old approach: innerHTML serialization"] -.->|"removed"| H["New approach: scope inheritance"]
File Changes1. packages/retend-web/source/dom-renderer.js
|
Code Review by Qodo
1. SVG child namespace regression
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
retend | 69529cb | Commit Preview URL Branch Preview URL |
May 10 2026, 03:37 PM |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc517667c6
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const defaultNamespace = props?.xmlns ?? inheritedNamespace; | ||
| let ns; | ||
| if (tagname === 'svg') { | ||
| ns = 'http://www.w3.org/2000/svg'; | ||
| } else if (tagname === 'math') { | ||
| ns = 'http://www.w3.org/1998/Math/MathML'; | ||
| } else { | ||
| ns = defaultNamespace; | ||
| if (tagname === 'svg') ns = SVG_NAMESPACE; | ||
| else if (tagname === 'math') ns = MATH_NAMESPACE; | ||
| else ns = defaultNamespace; |
There was a problem hiding this comment.
Keep internal teleport container in HTML namespace
This fallback makes every non-svg/math tag inherit the parent namespace, so a <Teleport> rendered inside <svg> now creates retend-teleport as an SVGElement instead of an HTMLElement. That breaks downstream logic that expects teleported containers to be HTML nodes (for example, copyComponentScreenshot only accepts __retendTeleportedContainer when instanceof HTMLElement), so teleported SVG components can no longer be captured correctly. Internal wrapper tags like retend-teleport should stay in HTML_NAMESPACE even when their source scope is SVG/MathML.
Useful? React with 👍 / 👎.
retend
retend-oxlint-plugin
retend-server
retend-start
retend-utils
retend-web
retend-web-devtools
commit: |
Introduce a scope for managing XML namespaces. This allows for proper handling of SVG and MathML elements within nested structures, including reactive branches and teleported content.
This change also improves the
createContainerlogic by inheriting namespaces from parent scopes and setting them explicitly when needed, rather than relying on string manipulation or re-serialization.