Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
349e2c0
Preserve matching prerendered DOM during interactive activation
ilonatommy Nov 3, 2026
edc32e7
Reconcile prerendered DOM positionally on interactive activation
ilonatommy Nov 4, 2026
122e153
Simplify initial prerendered DOM reconciliation
ilonatommy Nov 5, 2026
744c1cf
Fix prerendered DOM initializer ordering
ilonatommy Nov 5, 2026
a9efc5d
Simplify prerendered DOM adoption and check select defaults
ilonatommy Nov 6, 2026
e8adbbd
Merge main into prerendered DOM reconciliation
ilonatommy Nov 10, 2026
f6fac4f
Reduce duplicate prerendered DOM browser test cases
ilonatommy Nov 10, 2026
9380d58
Remove remaining duplicate runtime coverage from DOM adoption tests
ilonatommy Nov 10, 2026
840f788
Move structural DOM adoption coverage out of browser tests
ilonatommy Nov 10, 2026
b71b7ac
Remove added DOM adoption unit-test suite
ilonatommy Nov 10, 2026
8fe0082
Clarify prerendered DOM test flows and reuse interaction helpers
ilonatommy Nov 11, 2026
86559e8
Reduce prerendered DOM tests to expected behavior
ilonatommy Nov 11, 2026
0585311
Simplify prerendered DOM adoption planning
ilonatommy Nov 11, 2026
c9d612c
Preserve interactive input reset defaults during DOM adoption
ilonatommy Nov 11, 2026
904467b
Prerendered DOM v3: reuse enhanced navigation DOM diffing
ilonatommy Nov 18, 2026
922a8b4
Merge main into prerendered DOM reconciliation
ilonatommy Nov 18, 2026
9406ba8
Simplify prerendered DOM activation preview
ilonatommy Nov 18, 2026
c0984de
Reduce repeated prerendered DOM test assertions
ilonatommy Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Components/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ Prerendering and interactive rendering are separate executions. Prerendering cre

Activation information in the HTML identifies interactive roots and supplies the data needed to create them. It does not transfer ownership of the prerendered component instances. Any state required to avoid recomputation or preserve continuity must be captured during prerendering and restored by the interactive instance.

On the first interactive render, `Web.JS` renders an inert preview and reuses enhanced navigation's DOM diff to preserve compatible prerendered nodes, then binds events and references. Form controls retain user edits when their rendered defaults and relevant markup match; unsupported roots fall back to replacement. Later renders, circuit restoration, and enhanced navigation are unchanged.

A statically rendered parent can establish interactive roots, but the selected render mode defines an execution boundary. Components within an interactive hierarchy execute in the runtime that owns that hierarchy unless another independently activated root is established at an allowed boundary.

### Navigation and Document Lifetime
Expand Down
242 changes: 188 additions & 54 deletions src/Components/Web.JS/src/Rendering/BrowserRenderer.ts

Large diffs are not rendered by default.

53 changes: 32 additions & 21 deletions src/Components/Web.JS/src/Rendering/DomMerging/DomSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,25 @@ function preprocessAndSynchronizeDomContent(destination: CommentBoundedRange | N
synchronizeDomContentCore(destination, newContent);
}

function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newContent: Node) {
export function synchronizePrerenderedDom(destination: CommentBoundedRange, newContent: Node, onMatch: (destination: Node, source: Node) => boolean) {
synchronizeDomContentCore(destination, newContent, onMatch);
}

function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newContent: Node, onMatch?: (destination: Node, source: Node) => boolean) {
// Determine the destination's parent node, i.e., the node containing the children
// we intend to synchronize. This might sometimes be a logical parent.
let destinationParent: Node;
if (destination instanceof Node) {
destinationParent = destination;
} else {
destinationParent =
getLogicalParent(destination.startExclusive as unknown as LogicalElement) as unknown as Node ??
(onMatch ? undefined : getLogicalParent(destination.startExclusive as unknown as LogicalElement) as unknown as Node) ??
destination.startExclusive.parentNode!;
}

// If only one out of the destination and new content is a logical element, we normalize
// the other to also be a logical element
const isSynchronizingLogicalElements = isLogicalElement(destinationParent) || isLogicalElement(newContent);
const isSynchronizingLogicalElements = !onMatch && (isLogicalElement(destinationParent) || isLogicalElement(newContent));
if (isSynchronizingLogicalElements) {
toLogicalElement(destinationParent, /* allowExistingContents */ true);
toLogicalElement(newContent, /* allowExistingContents */ true);
Expand All @@ -91,7 +95,7 @@ function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newC
const editScript = computeEditScript(
originalNodesForDiff,
newNodesForDiff,
domNodeComparer
onMatch ? (a, b) => domNodeComparer(a, b, true) : domNodeComparer
);

let destinationWalker: EditWalker;
Expand All @@ -106,7 +110,7 @@ function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newC

// Handle any common leading items
for (let i = 0; i < editScript.skipCount; i++) {
treatAsMatch(destinationWalker.current, sourceWalker.current);
treatAsMatch(destinationWalker.current, sourceWalker.current, onMatch);
destinationWalker.advance();
sourceWalker.advance();
}
Expand All @@ -120,27 +124,28 @@ function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newC
const operation = edits[editIndex];
switch (operation) {
case Operation.Keep: {
treatAsMatch(destinationWalker.current, sourceWalker.current);
treatAsMatch(destinationWalker.current, sourceWalker.current, onMatch);
destinationWalker.advance();
sourceWalker.advance();
break;
}
case Operation.Update: {
treatAsSubstitution(destinationWalker.current, sourceWalker.current);
onMatch?.(destinationWalker.current, sourceWalker.current);
destinationWalker.advance();
sourceWalker.advance();
break;
}
case Operation.Delete: {
const nodeToRemove = destinationWalker.current;
destinationWalker.advance();
treatAsDeletion(nodeToRemove, destinationParent);
treatAsDeletion(nodeToRemove, destinationParent, !!onMatch);
break;
}
case Operation.Insert: {
const nodeToInsert = sourceWalker.current;
sourceWalker.advance();
treatAsInsertion(nodeToInsert, destinationWalker.current, destinationParent);
treatAsInsertion(nodeToInsert, destinationWalker.current, destinationParent, !!onMatch);
break;
}
default:
Expand All @@ -152,7 +157,7 @@ function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newC
// These can only exist if there were some edits, otherwise everything would be in the set of common leading items
const endAtNodeExclOrNull = destination instanceof Node ? null : destination.endExclusive;
while (destinationWalker.current !== endAtNodeExclOrNull) {
treatAsMatch(destinationWalker.current, sourceWalker.current);
treatAsMatch(destinationWalker.current, sourceWalker.current, onMatch);
destinationWalker.advance();
sourceWalker.advance();
}
Expand All @@ -164,7 +169,8 @@ function synchronizeDomContentCore(destination: CommentBoundedRange | Node, newC
}
}

function treatAsMatch(destination: Node, source: Node) {
function treatAsMatch(destination: Node, source: Node, onMatch?: (destination: Node, source: Node) => boolean) {
const preserveFormState = onMatch?.(destination, source) ?? false;
switch (destination.nodeType) {
case Node.TEXT_NODE:
break;
Expand All @@ -187,7 +193,7 @@ function treatAsMatch(destination: Node, source: Node) {
// Don't sync DOM content for already-interactive components because their content is managed
// by the renderer.
} else {
synchronizeDomContentCore(destination, source);
synchronizeDomContentCore(destination, source, onMatch);
}
}
break;
Expand All @@ -197,15 +203,17 @@ function treatAsMatch(destination: Node, source: Node) {
// The destination element's content and attributes should be retained.
} else {
const editableElementValue = getEditableElementValue(source as Element);
synchronizeAttributes(destination as Element, source as Element);
applyAnyDeferredValue(destination as Element);
synchronizeDomContentCore(destination as Element, source as Element);
if (!preserveFormState) {
synchronizeAttributes(destination as Element, source as Element);
applyAnyDeferredValue(destination as Element);
}
synchronizeDomContentCore(destination as Element, source as Element, onMatch);

// This is a much simpler alternative to the deferred-value-assignment logic we use in interactive rendering.
// Because this sync algorithm goes depth-first, we know all the attributes and descendants are fully in sync
// by now, so setting any "special value" property is just a matter of assigning it right now (we don't have
// to be concerned that it's invalid because it doesn't correspond to an <option> child or a min/max attribute).
if (editableElementValue !== null) {
if (!preserveFormState && editableElementValue !== null) {
ensureEditableValueSynchronized(destination as Element, editableElementValue);
Comment on lines +216 to 217
}
}
Expand All @@ -230,8 +238,8 @@ function treatAsSubstitution(destination: Node, source: Node) {
}
}

function treatAsDeletion(nodeToDelete: Node, parentNode: Node) {
if (isLogicalElement(parentNode)) {
function treatAsDeletion(nodeToDelete: Node, parentNode: Node, physical = false) {
if (!physical && isLogicalElement(parentNode)) {
// It's not safe to call 'removeLogicalChild' here because it recursively removes
// logical descendants from their parents, and that can potentially interfere with
// renderer-managed DOM. Instead, we insert the logical element into a new document
Expand All @@ -244,8 +252,8 @@ function treatAsDeletion(nodeToDelete: Node, parentNode: Node) {
}
}

function treatAsInsertion(nodeToInsert: Node, nextNode: Node | null, parentNode: Node) {
if (isLogicalElement(parentNode)) {
function treatAsInsertion(nodeToInsert: Node, nextNode: Node | null, parentNode: Node, physical = false) {
if (!physical && isLogicalElement(parentNode)) {
insertLogicalChildBefore(nodeToInsert, parentNode as unknown as LogicalElement, nextNode as unknown as LogicalElement);
} else {
// If the parent node is not a logical element, that means
Expand All @@ -256,6 +264,9 @@ function treatAsInsertion(nodeToInsert: Node, nextNode: Node | null, parentNode:
}

// Find and register descriptors in new content
if (physical) {
return;
}
const iterator = document.createNodeIterator(nodeToInsert, NodeFilter.SHOW_COMMENT);
while (iterator.nextNode()) {
const logicalRootDescriptor = getLogicalRootDescriptor(iterator.referenceNode as unknown as LogicalElement);
Expand All @@ -265,12 +276,12 @@ function treatAsInsertion(nodeToInsert: Node, nextNode: Node | null, parentNode:
}
}

function domNodeComparer(a: Node, b: Node): UpdateCost {
function domNodeComparer(a: Node, b: Node, physical = false): UpdateCost {
if (a.nodeType !== b.nodeType) {
return UpdateCost.Infinite;
}

if (isLogicalElement(a) !== isLogicalElement(b)) {
if (!physical && isLogicalElement(a) !== isLogicalElement(b)) {
// We cannot merge logical elements with non-logical elements.
return UpdateCost.Infinite;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// and the SSR DOM merging logic.

export const deferredValuePropname = '_blazorDeferredValue';
export const internalAttributeNamePrefix = '__internal_';

export function tryApplySpecialProperty(element: Element, name: string, value: string | null) {
switch (name) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Web.JS/src/Rendering/FocusOnNavigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function restoreNavigationFocus(focus: PendingNavigationFocus): void {
return;
}

// Match FocusOnNavigate's document.querySelector order, limited to the replaced root.
// Match FocusOnNavigate's document.querySelector order, limited to the activated root.
const rootElements = getElementsInLogicalRoot(focus.root);
const replacement = Array.from(document.querySelectorAll(focus.selector)).find(element => isInLogicalRoot(rootElements, element));
if (!replacement) {
Expand All @@ -130,8 +130,7 @@ export function restoreNavigationFocus(focus: PendingNavigationFocus): void {
}

function canRestoreFocus(focus: PendingNavigationFocus): boolean {
return !focus.element.isConnected
&& (document.activeElement === null || document.activeElement === document.body)
return (document.activeElement === null || document.activeElement === document.body)
&& currentFocusOnNavigateElement === focus.owner
&& focus.owner.isConnected
&& focus.owner.getAttribute('selector') === focus.selector;
Expand Down
16 changes: 15 additions & 1 deletion src/Components/Web.JS/src/Rendering/LogicalElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ export function emptyLogicalElement(element: LogicalElement): void {
}
}

export function resetLogicalChildren(element: LogicalElement): void {
const children = getLogicalChildrenArray(element);
for (const child of children) {
delete child[logicalParentPropname];
}
children.length = 0;
}

export function adoptLogicalChild(child: Node, parent: LogicalElement, childIndex: number): void {
const logicalChild = toLogicalElement(child, true);
getLogicalChildrenArray(parent).splice(childIndex, 0, logicalChild);
logicalChild[logicalParentPropname] = parent;
}

export function createAndInsertLogicalContainer(parent: LogicalElement, childIndex: number): LogicalElement {
const containerElement = document.createComment('!');
insertLogicalChild(containerElement, parent, childIndex);
Expand Down Expand Up @@ -387,7 +401,7 @@ function appendDomNode(child: Node, parent: LogicalElement) {
}
}

function getLogicalDomNodeContainer(parent: Node): Element | DocumentFragment {
export function getLogicalDomNodeContainer(parent: Node): Element | DocumentFragment {
if (parent instanceof HTMLTemplateElement) {
return parent.content;
}
Expand Down
Loading
Loading