diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp
index edc2348c7763..20778c9466f7 100644
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -823,11 +823,11 @@ nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
} else {
ClearHasValidDir();
ClearHasFixedDir();
- ClearHasDirAuto();
- ClearHasDirAutoSet();
if (NodeInfo()->Equals(nsGkAtoms::bdi)) {
SetHasDirAuto();
} else {
+ ClearHasDirAuto();
+ ClearHasDirAutoSet();
dir = RecomputeDirectionality(this, aNotify);
}
}