Repository navigation
Parse raw html against the element it is inserted into, so svg keeps its namespace - #893
Merged
Merged
Conversation
`RawText` assigned `innerHTML` on a `<template>`, so the html parser had no element to parse against and put every node in the xhtml namespace. Inside an `<svg>` that made `<circle>` an unknown html element, which the browser lays out as nothing: the server-rendered markup showed the shape and it vanished as soon as the component hydrated. The markup is now parsed with `Range.createContextualFragment` against the nearest ancestor element, so the nodes come out in that element's namespace. That also covers markup that is only valid inside a specific parent, such as a `<td>` in a `<tr>`. The template is kept for when there is no element to parse against, which is what a fragment at the root of a component tree is. Fixes schultek#567
diegolopezrm
force-pushed
the
fix/raw-text-svg-namespace
branch
from
September 22, 2026 17:59
1b0000a to
8c3fd0b
Compare
Package Version ReportThe following packages have been updated: |
schultek
approved these changes
Sep 24, 2026
schultek
left a comment
Owner
There was a problem hiding this comment.
LGTM. I didn't know about the Range.createContextualFragment API, this is great!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
raw()put its nodes in the xhtml namespace, so svg markup rendered as nothing.The markup was parsed by assigning
innerHTMLon a<template>, where the html parser has no element to parse against.<circle>therefore came out as an unknown html element rather than an svg one — present in the dom, laid out as nothing. Server-rendered output showed the shape, and it disappeared the moment the component hydrated, which is what #567 reports.It is now parsed with
Range.createContextualFragmentagainst the nearest ancestor element, so the nodes come out in that element's namespace. The element is already reachable from the component's element throughparentRenderObjectElement; the chain is walked until an element turns up, because a fragment renders into aDocumentFragment. The template path is kept for when there is no element to parse against, which is a fragment at the root of a component tree.Parsing against an element also settles markup that is only valid inside a specific parent, such as a
<td>in a<tr>.raw_text_web.dartis identical onnext, so this applies there unchanged.Type of Change
Tests
packages/jaspr/test/dom/html/raw_text_browser_test.dart, five cases:<circle>) comes out in the svg namespace<g>with a child) keeps the namespace all the way down<svg>element inside html still works, which the html parser already handled — there to catch a fix that special-cases the namespace too eagerlyThe two svg fragment cases and the hydration case fail before the change and pass after.
dart test -p chromeanddart test -p vmare green inpackages/jaspr.Fixes #567