Bug 1818239, latter reload should win, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D173169
This commit is contained in:
Olli Pettay 2023-03-22 14:51:47 +00:00
parent d3637730d2
commit 415571974a
3 changed files with 23 additions and 0 deletions

View File

@ -4061,6 +4061,7 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
MOZ_LOG(gSHLog, LogLevel::Debug, ("nsDocShell %p Reload", this));
bool forceReload = IsForceReloadType(loadType);
if (!XRE_IsParentProcess()) {
++mPendingReloadCount;
RefPtr<nsDocShell> docShell(this);
nsCOMPtr<nsIContentViewer> cv(mContentViewer);
NS_ENSURE_STATE(cv);
@ -4095,6 +4096,12 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
}
});
// Decrease mPendingReloadCount before any other early returns!
if (--(docShell->mPendingReloadCount) > 0) {
return;
}
if (stopDetector->Canceled()) {
return;
}

View File

@ -1297,6 +1297,8 @@ class nsDocShell final : public nsDocLoader,
uint64_t mChannelToDisconnectOnPageHide;
uint32_t mPendingReloadCount = 0;
// The following two fields cannot be declared as bit fields
// because of uses with AutoRestore.
bool mCreatingDocument; // (should be) debugging only

View File

@ -25,6 +25,20 @@
win.close();
});
add_task(async function runTest2() {
let win = window.open("file_load_during_reload.html");
await promiseForLoad();
win.history.replaceState("", "", "?1");
win.location.reload();
win.history.pushState("", "", "?2");
win.location.reload();
await promiseForLoad();
ok(win.location.href.includes("2"), "Should have loaded the second page.");
win.close();
});
</script>
</head>
<body>