Repository navigation
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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.
[blazor] Avoid quadratic MarkupString insertion
Avoid quadratic work when rendering large markup fragments.
Description
Each
MarkupStringis rendered into a newly created logical container. Its top-level nodes can therefore be appended in order without scanning the container's existing logical siblings before each insertion. After insertion (including synchronous script execution), compact the logical-children array once, dropping nodes that are disconnected from the DOM. This changes markup insertion from repeated sibling scans to a single linear cleanup pass, without changing orphan cleanup for other logical insertions.For a fresh container, the previous per-insertion scan never changed where nodes were placed: every insertion was already an append. DOM output, script execution order, and each node's position when its script runs are therefore unchanged. Parent indexes are unaffected because the markup container is a single logical child of its parent, and #66007's orphan handling still applies to every other insertion, including creation of the markup container.
Behavior notes
A top-level markup node now remains tracked exactly when it still has a DOM parent at the moment markup insertion finishes. Previously, this depended on whether a later insertion happened to scan after the node was detached. This only affects scripts or custom elements that externally mutate Blazor-rendered markup:
<script>, is now dropped from tracking, so the next markup update no longer throwsCannot read properties of null (reading 'removeChild').Nodes detached asynchronously after insertion completes are handled as before.
Benchmark
Five-run medians from the same in-tree interactive Server sample using Playwright WebKit 27.2 on macOS ARM64. Timings are click-to-DOM-update, including local Server processing and transport; they are not a comparison with .NET 10. Values are original implementation / MutationObserver implementation previously on this PR / current fresh-container implementation.
Validation
npm test --workspace @microsoft/microsoft.aspnetcore.components.web.js -- --runInBand test/LogicalElements.test.ts test/DomSync.test.ts test/BrowserRenderer.updateText.test.ts— 54 passed.Targeted ESLint on
BrowserRenderer.tsandLogicalElements.ts— 0 errors (existing warnings only).The E2E project built successfully. Focused Selenium run with Chromium on macOS ARM64 — 9 passed, including flat and wrapped markup, script removal/reparenting and clear, markup blocks, and enhanced navigation. The final self-removing-script test fails against both the previous MutationObserver implementation and the original implementation, and passes with this cleanup approach.
Ownership behavior was compared in a temporary interactive Server sample with WebKit 27.2, using the original and current bundles (10 runs each, identical outcomes per version). These ownership cases are not covered by permanent tests because they depend on external mutation of Blazor-managed DOM.
A full framework build did not complete because of an unrelated
MSB4006circular dependency involvingGetFilesToPublishinMicrosoft.AspNetCore.App.Runtime.sfxproj; focused in-tree builds succeeded.Fixes #70503
Note
This PR description was generated with the assistance of GitHub Copilot.