Skip to content

Support enhanced nav updates to link tag integrity #55163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export function synchronizeAttributes(destination: Element, source: Element) {

// Skip most of the work in the common case where all attributes are unchanged and are even still in the same order
if (!attributeSetsAreIdentical(destAttrs, sourceAttrs)) {
// Certain element types may have special rules about how to update their attributes,
// or might require us to synchronize DOM properties as well as attributes
if (destination instanceof HTMLLinkElement || destination instanceof HTMLScriptElement) {
destination.integrity = (source as HTMLLinkElement | HTMLScriptElement).integrity;
}

// Now do generic unordered attribute synchronization
const remainingDestAttrs = new Map<string, Attr>();
for (const destAttr of destination.attributes as any) {
remainingDestAttrs.set(destAttr.name, destAttr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,25 @@ public void CanReceiveNullParameterValueOnEnhancedNavigation(string renderMode)
Assert.DoesNotContain(logs, log => log.Message.Contains("Error"));
}

[Fact]
public void CanUpdateHrefOnLinkTagWithIntegrity()
{
// Represents issue https://github.com/dotnet/aspnetcore/issues/54250
// Previously, if the "integrity" attribute appeared after "href", then we'd be unable
// to update "href" because the new content wouldn't match the existing "integrity".
// This is fixed by ensuring we update "integrity" first in all cases.

Navigate($"{ServerPathBase}/nav/page-with-link-tag/1");

var originalH1Elem = Browser.Exists(By.TagName("h1"));
Browser.Equal("PageWithLinkTag 1", () => originalH1Elem.Text);
Browser.Equal("rgba(255, 0, 0, 1)", () => originalH1Elem.GetCssValue("color"));

Browser.Exists(By.LinkText("Go to page with link tag 2")).Click();
Browser.Equal("PageWithLinkTag 2", () => originalH1Elem.Text);
Browser.Equal("rgba(0, 0, 255, 1)", () => originalH1Elem.GetCssValue("color"));
}

private void AssertEnhancedUpdateCountEquals(long count)
=> Browser.Equal(count, () => ((IJavaScriptExecutor)Browser).ExecuteScript("return window.enhancedPageUpdateCount;"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/nav/page-with-link-tag/1"

<h1>PageWithLinkTag 1</h1>

<p>The header should be red</p>

<a href="nav/page-with-link-tag/2">Go to page with link tag 2</a>

<link rel="stylesheet" href="css/cssfile1.css" integrity="sha384-8mci8UV9AaVJGRJs90vuFCcaqfnGDVJaH+Uh1YRQk0Imw3L4+hBzIc4qL+FmyiF0" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/nav/page-with-link-tag/2"

<h1>PageWithLinkTag 2</h1>

<p>The header should be blue</p>

<a href="nav/page-with-link-tag/1">Go to page with link tag 1</a>

<link rel="stylesheet" href="css/cssfile2.css" integrity="sha384-sfRwKnaRYdL1d+7xYj26gW0zWRIfmw+134w0KCaG6tGHXTkP+duQxbC9Ouukgv32" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cssfile1.css eol=lf
cssfile2.css eol=lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Used by PageWithLinkTag1 */
h1 {
color: rgba(255, 0, 0, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Used by PageWithLinkTag2 */
h1 {
color: rgba(0, 0, 255, 1);
}