Skip to content

Commit fecba44

Browse files
committed
Disable preloading for enhanced navigation
1 parent 231b0aa commit fecba44

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ private void WriteComponentHtml(int componentId, TextWriter output, bool allowBo
324324
}
325325
}
326326

327-
private static bool IsProgressivelyEnhancedNavigation(HttpRequest request)
327+
internal static bool IsProgressivelyEnhancedNavigation(HttpRequest request)
328328
{
329329
// For enhanced nav, the Blazor JS code controls the "accept" header precisely, so we can be very specific about the format
330330
var accept = request.Headers.Accept;

src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public Task SetParametersAsync(ParameterView parameters)
124124

125125
private void PreloadWebAssemblyAssets()
126126
{
127+
if (EndpointHtmlRenderer.IsProgressivelyEnhancedNavigation(_httpContext.Request))
128+
{
129+
return;
130+
}
131+
127132
var preloads = _httpContext.GetEndpoint()?.Metadata.GetMetadata<ResourcePreloadCollection>();
128133
if (preloads != null && preloads.TryGetAssets("webassembly", out var preloadAssets))
129134
{

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-
export function attributeSetsAreIdentical(destAttrs: NamedNodeMap, sourceAttrs: NamedNodeMap): boolean {
46+
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: 1 addition & 17 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 { attributeSetsAreIdentical, synchronizeAttributes } from './AttributeSync';
8+
import { synchronizeAttributes } from './AttributeSync';
99
import { cannotMergeDueToDataPermanentAttributes, isDataPermanentElement } from './DataPermanentElementSync';
1010
import { UpdateCost, ItemList, Operation, computeEditScript } from './EditScript';
1111

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

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) {
320-
return UpdateCost.Infinite;
321-
}
322-
323311
return UpdateCost.None;
324312
case Node.DOCUMENT_TYPE_NODE:
325313
// It's invalid to insert or delete doctype, and we have no use case for doing that. So just skip such
@@ -331,10 +319,6 @@ function domNodeComparer(a: Node, b: Node): UpdateCost {
331319
}
332320
}
333321

334-
function isPreloadElement(el: Element): boolean {
335-
return el.tagName === 'LINK' && el.attributes.getNamedItem('rel')?.value === 'preload';
336-
}
337-
338322
function upgradeComponentCommentsToLogicalRootComments(root: Node): ComponentDescriptor[] {
339323
const serverDescriptors = discoverComponents(root, 'server') as ServerComponentDescriptor[];
340324
const webAssemblyDescriptors = discoverComponents(root, 'webassembly') as WebAssemblyComponentDescriptor[];

0 commit comments

Comments
 (0)