diff --git a/Source/WebCore/html/HTMLElement.cpp b/Source/WebCore/html/HTMLElement.cpp
index f6bab74abf6b4..8dfd40d59d1f2 100644
--- a/Source/WebCore/html/HTMLElement.cpp
+++ b/Source/WebCore/html/HTMLElement.cpp
@@ -1349,15 +1349,15 @@ void HTMLElement::queuePopoverToggleEventTask(PopoverVisibilityState oldState, P
ExceptionOr HTMLElement::showPopover(const HTMLFormControlElement* invoker)
{
- if (popoverData())
- popoverData()->setInvoker(invoker);
-
auto check = checkPopoverValidity(*this, PopoverVisibilityState::Hidden);
if (check.hasException())
return check.releaseException();
if (!check.returnValue())
return { };
+ if (popoverData())
+ popoverData()->setInvoker(invoker);
+
ASSERT(!isInTopLayer());
PopoverData::ScopedStartShowingOrHiding showOrHidingPopoverScope(*this);