Add MathML namespace support for interactive rendering#64632
Merged
Conversation
Fixes #60064 MathML elements were not rendering correctly when added with interactive content because they were being created using document.createElement() instead of document.createElementNS() with the MathML namespace. Changes: - Add isMathMLElement() helper function in LogicalElements.ts - Update insertElement() to use createElementNS for MathML elements - Update parseMarkup() to handle MathML content - Add E2E tests for MathML rendering
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for rendering MathML elements with the correct namespace in Blazor's interactive renderer. Previously, MathML elements were created using document.createElement() which resulted in incorrect rendering. The fix mirrors the existing SVG namespace handling by using document.createElementNS() with the MathML namespace URI.
Key changes:
- Added
isMathMLElement()helper function to detect MathML context - Updated element creation and markup parsing to handle MathML namespace
- Added comprehensive E2E tests covering interactive, static, nested, conditional, and complex MathML scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Components/Web.JS/src/Rendering/LogicalElements.ts |
Added isMathMLElement() helper function to detect if an element is in MathML context |
src/Components/Web.JS/src/Rendering/BrowserRenderer.ts |
Updated insertElement() and parseMarkup() to create MathML elements with correct namespace, added shared MathML parsing element |
src/Components/test/testassets/BasicTestApp/MathMLComponent.razor |
Test component with 5 MathML scenarios: interactive, static, child component, conditional, and complex formula |
src/Components/test/testassets/BasicTestApp/MathMLRowComponent.razor |
Child component for testing nested MathML rendering |
src/Components/test/testassets/BasicTestApp/Index.razor |
Added MathMLComponent to the test component selector dropdown |
src/Components/test/E2ETest/Tests/MathMLTest.cs |
E2E test suite with 5 tests verifying correct MathML namespace handling across various scenarios |
ilonatommy
approved these changes
Dec 4, 2025
Member
ilonatommy
left a comment
There was a problem hiding this comment.
Look good, even though it's a bunch of new e2e tests for this narrow use case.
Member
Author
That's fair. We can choose to trim down the set in the future. |
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.
Summary
Fixes #60064
MathML elements (
<math>,<mrow>,<mi>, etc.) were not rendering correctly when added with interactive content in Blazor. The issue was that these elements were being created usingdocument.createElement()instead ofdocument.createElementNS()with the MathML namespace (http://www.w3.org/1998/Math/MathML).This is similar to how SVG elements are handled in the renderer.
Changes
Core Fix
isMathMLElement()helper function to detect if an element is inside a MathML contextsharedMathMLElemForParsingfor parsing MathML markup contentinsertElement()to create MathML elements with the correct namespace usingcreateElementNS('http://www.w3.org/1998/Math/MathML', tagName)parseMarkup()to handle MathML contentTests
MathMLComponent.razor- Test component with various MathML scenariosMathMLRowComponent.razor- Child component for testing nested MathMLMathMLTest.cs- E2E tests covering:Testing
All 5 new E2E tests pass:
CanRenderMathMLWithCorrectNamespaceCanRenderStaticMathMLWithCorrectNamespaceCanRenderMathMLChildComponentWithCorrectNamespaceCanRenderConditionalMathMLWithCorrectNamespaceCanRenderComplexMathMLWithCorrectNamespace