Skip to content

Commit 19a7642

Browse files
Support enhanced nav updates to link tag integrity (#55163)
1 parent b83e1e1 commit 19a7642

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export function synchronizeAttributes(destination: Element, source: Element) {
77

88
// Skip most of the work in the common case where all attributes are unchanged and are even still in the same order
99
if (!attributeSetsAreIdentical(destAttrs, sourceAttrs)) {
10+
// Certain element types may have special rules about how to update their attributes,
11+
// or might require us to synchronize DOM properties as well as attributes
12+
if (destination instanceof HTMLLinkElement || destination instanceof HTMLScriptElement) {
13+
destination.integrity = (source as HTMLLinkElement | HTMLScriptElement).integrity;
14+
}
15+
16+
// Now do generic unordered attribute synchronization
1017
const remainingDestAttrs = new Map<string, Attr>();
1118
for (const destAttr of destination.attributes as any) {
1219
remainingDestAttrs.set(destAttr.name, destAttr);

src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,25 @@ public void CanReceiveNullParameterValueOnEnhancedNavigation(string renderMode)
643643
Assert.DoesNotContain(logs, log => log.Message.Contains("Error"));
644644
}
645645

646+
[Fact]
647+
public void CanUpdateHrefOnLinkTagWithIntegrity()
648+
{
649+
// Represents issue https://github.com/dotnet/aspnetcore/issues/54250
650+
// Previously, if the "integrity" attribute appeared after "href", then we'd be unable
651+
// to update "href" because the new content wouldn't match the existing "integrity".
652+
// This is fixed by ensuring we update "integrity" first in all cases.
653+
654+
Navigate($"{ServerPathBase}/nav/page-with-link-tag/1");
655+
656+
var originalH1Elem = Browser.Exists(By.TagName("h1"));
657+
Browser.Equal("PageWithLinkTag 1", () => originalH1Elem.Text);
658+
Browser.Equal("rgba(255, 0, 0, 1)", () => originalH1Elem.GetCssValue("color"));
659+
660+
Browser.Exists(By.LinkText("Go to page with link tag 2")).Click();
661+
Browser.Equal("PageWithLinkTag 2", () => originalH1Elem.Text);
662+
Browser.Equal("rgba(0, 0, 255, 1)", () => originalH1Elem.GetCssValue("color"));
663+
}
664+
646665
private void AssertEnhancedUpdateCountEquals(long count)
647666
=> Browser.Equal(count, () => ((IJavaScriptExecutor)Browser).ExecuteScript("return window.enhancedPageUpdateCount;"));
648667

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@page "/nav/page-with-link-tag/1"
2+
3+
<h1>PageWithLinkTag 1</h1>
4+
5+
<p>The header should be red</p>
6+
7+
<a href="nav/page-with-link-tag/2">Go to page with link tag 2</a>
8+
9+
<link rel="stylesheet" href="css/cssfile1.css" integrity="sha384-8mci8UV9AaVJGRJs90vuFCcaqfnGDVJaH+Uh1YRQk0Imw3L4+hBzIc4qL+FmyiF0" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@page "/nav/page-with-link-tag/2"
2+
3+
<h1>PageWithLinkTag 2</h1>
4+
5+
<p>The header should be blue</p>
6+
7+
<a href="nav/page-with-link-tag/1">Go to page with link tag 1</a>
8+
9+
<link rel="stylesheet" href="css/cssfile2.css" integrity="sha384-sfRwKnaRYdL1d+7xYj26gW0zWRIfmw+134w0KCaG6tGHXTkP+duQxbC9Ouukgv32" />
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cssfile1.css eol=lf
2+
cssfile2.css eol=lf
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Used by PageWithLinkTag1 */
2+
h1 {
3+
color: rgba(255, 0, 0, 1);
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Used by PageWithLinkTag2 */
2+
h1 {
3+
color: rgba(0, 0, 255, 1);
4+
}

0 commit comments

Comments
 (0)