Skip to content

Commit 231b0aa

Browse files
committed
Compare preload attributes
1 parent bb2d778 commit 231b0aa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Components/Web.JS/src/Rendering/DomMerging/AttributeSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function synchronizeAttributes(destination: Element, source: Element) {
4343
}
4444
}
4545

46-
function attributeSetsAreIdentical(destAttrs: NamedNodeMap, sourceAttrs: NamedNodeMap): boolean {
46+
export function attributeSetsAreIdentical(destAttrs: NamedNodeMap, sourceAttrs: NamedNodeMap): boolean {
4747
const destAttrsLength = destAttrs.length;
4848
if (destAttrsLength !== sourceAttrs.length) {
4949
return false;

src/Components/Web.JS/src/Rendering/DomMerging/DomSync.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AutoComponentDescriptor, ComponentDescriptor, ServerComponentDescriptor
55
import { isInteractiveRootComponentElement } from '../BrowserRenderer';
66
import { applyAnyDeferredValue } from '../DomSpecialPropertyUtil';
77
import { LogicalElement, getLogicalChildrenArray, getLogicalNextSibling, getLogicalParent, getLogicalRootDescriptor, insertLogicalChild, insertLogicalChildBefore, isLogicalElement, toLogicalElement, toLogicalRootCommentElement } from '../LogicalElements';
8-
import { synchronizeAttributes } from './AttributeSync';
8+
import { attributeSetsAreIdentical, synchronizeAttributes } from './AttributeSync';
99
import { cannotMergeDueToDataPermanentAttributes, isDataPermanentElement } from './DataPermanentElementSync';
1010
import { UpdateCost, ItemList, Operation, computeEditScript } from './EditScript';
1111

@@ -308,8 +308,15 @@ function domNodeComparer(a: Node, b: Node): UpdateCost {
308308
return UpdateCost.Infinite;
309309
}
310310

311-
// Always treat "preloads" as new elements.
312-
if (isPreloadElement(a as Element) || isPreloadElement(b as Element)) {
311+
// If both elements are the same preload (based on all attributes), we need to match them and do nothing;
312+
// Otherwise, browser would trigger a new preload request.
313+
// If attributes don't match, we can't simply update the element, because browser could trigger
314+
// an invalid preload request based on attribute order.
315+
const aIsPreload = isPreloadElement(a as Element);
316+
const bIsPreload = isPreloadElement(b as Element);
317+
if (aIsPreload && bIsPreload && attributeSetsAreIdentical((a as Element).attributes, (b as Element).attributes)) {
318+
return UpdateCost.None;
319+
} else if (aIsPreload || bIsPreload) {
313320
return UpdateCost.Infinite;
314321
}
315322

0 commit comments

Comments
 (0)