diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index b10d4abfa7cc..452a162d4f5f 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -4699,6 +4699,22 @@ nsresult HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak(
return NS_OK;
}
if (unnecessaryLineBreak->IsHTMLBRElement()) {
+ // If the found unnecessary is a preceding one of a mailcite which is a
+ // styled as block, we need to preserve the element for the
+ // serializer to cause a line break before the mailcite.
+ if (IsPlaintextMailComposer()) {
+ const WSScanResult nextThing =
+ WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
+ WSRunScanner::Scan::All,
+ unnecessaryLineBreak->After(),
+ BlockInlineCheck::UseComputedDisplayOutsideStyle);
+ if (nextThing.ReachedOtherBlockElement() &&
+ HTMLEditUtils::IsMailCite(*nextThing.ElementPtr()) &&
+ HTMLEditUtils::IsInlineContent(
+ *nextThing.ElementPtr(), BlockInlineCheck::UseHTMLDefaultStyle)) {
+ return NS_OK;
+ }
+ }
// If the invisible break is a placeholder of ancestor inline elements, we
// should not delete it to allow users to insert text with the format
// specified by them.
diff --git a/editor/libeditor/tests/mochitest.toml b/editor/libeditor/tests/mochitest.toml
index 25597ff5c258..a1f1385d475f 100644
--- a/editor/libeditor/tests/mochitest.toml
+++ b/editor/libeditor/tests/mochitest.toml
@@ -479,6 +479,9 @@ skip-if = ["display == 'wayland'"] # Bug 1935188
["test_mailcite_backspace_at_end_of_inline_reply.html"]
skip-if = ["xorigin"] # Testing internal API for comm-central
+["test_mailcite_keep_preceding_br_after_insert.html"]
+skip-if = ["xorigin"] # Testing internal API for comm-central
+
["test_mailcite_keep_trailing_br_after_delete.html"]
skip-if = ["xorigin"] # Testing internal API for comm-central
diff --git a/editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html b/editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html
new file mode 100644
index 000000000000..6169b16d793c
--- /dev/null
+++ b/editor/libeditor/tests/test_mailcite_keep_preceding_br_after_insert.html
@@ -0,0 +1,73 @@
+
+
+
+
+Preceding <br> of a mailcite which is a blocked <span>
+
+
+
+
+
+
+
+