Bug 1825745 - Fix intermittent failure of testing/web-platform/tests/html/browsers/browsing-the-web/navigating-across-documents/replace-before-load/form-submit-button-click.html. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D180534
This commit is contained in:
Peter Van der Beken
2023-06-22 08:07:06 +00:00
parent 9414df2959
commit 80f6668b4e

View File

@@ -2266,7 +2266,20 @@ void nsGenericHTMLElement::Click(CallerType aCallerType) {
RefPtr<nsPresContext> context;
if (doc) {
context = doc->GetPresContext();
PresShell* presShell = doc->GetPresShell();
if (!presShell) {
// We need the nsPresContext for dispatching the click event. In some
// rare cases we need to flush notifications to force creation of the
// nsPresContext here (for example when a script calls button.click()
// from script early during page load). We only flush the notifications
// if the PresShell hasn't been created yet, to limit the performance
// impact.
doc->FlushPendingNotifications(FlushType::EnsurePresShellInitAndFrames);
presShell = doc->GetPresShell();
}
if (presShell) {
context = presShell->GetPresContext();
}
}
SetHandlingClick();