commit 9243421d508e03d3cd094fb76c109050c7234843
parent bdaf95cfcd584a128b55f1c73a5aa0168d8d23e4
Author: Andreas Farre <farre@mozilla.com>
Date: Tue, 18 Nov 2025 10:48:53 +0000
Bug 1998121 - Manually change LOAD_LINK to LOAD_NORMAL_REPLACE. r=dom-core,smaug
Differential Revision: https://phabricator.services.mozilla.com/D272864
Diffstat:
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
@@ -9434,8 +9434,15 @@ static void MaybeConvertToReplaceLoad(nsDocShellLoadState* aLoadState,
*aExtantDocument))
? "needs completely loaded document"
: "navigation must be a replace");
- aLoadState->SetLoadType(MaybeAddLoadFlags(
- aLoadState->LoadType(), nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY));
+ // There is no replace variant for LOAD_LINK, so we convert it to
+ // LOAD_NORMAL_REPLACE just like in nsDocShell::OnNewURI.
+ if (aLoadState->LoadType() == LOAD_LINK) {
+ aLoadState->SetLoadType(LOAD_NORMAL_REPLACE);
+ } else {
+ aLoadState->SetLoadType(
+ MaybeAddLoadFlags(aLoadState->LoadType(),
+ nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY));
+ }
aLoadState->SetHistoryBehavior(NavigationHistoryBehavior::Replace);
} else {
aLoadState->SetHistoryBehavior(NavigationHistoryBehavior::Push);
diff --git a/testing/web-platform/tests/navigation-api/navigate-event/navigate-anchor-same-url.html b/testing/web-platform/tests/navigation-api/navigate-event/navigate-anchor-same-url.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<a id="a" href="/navigation-api/navigate-event/navigate-anchor-same-url.html"></a>
+<script>
+promise_test(async t => {
+ await new Promise(resolve => window.addEventListener('load', resolve, {once: true}));
+
+ const { promise, resolve } = Promise.withResolvers();
+ navigation.onnavigate = t.step_func_done(e => {
+ assert_equals(e.navigationType, "replace");
+ assert_equals(new URL(e.destination.url).pathname,
+ "/navigation-api/navigate-event/navigate-anchor-same-url.html");
+ resolve();
+ e.intercept({handler: () => {}});
+ });
+ a.click();
+
+ return promise;
+}, "<a> to identical url is a replace navigation");
+</script>