Skip to content

Commit 39742e3

Browse files
committed
[FIX] mail: strip bg-o-color class from body_html
When a mass mailing block uses a `bg-o-color-N` theme color class, the mailing's `body_arch` stores the class and `convert_inline` correctly inlines the resolved color into `body_html`, matching the website palette at save time. The class also stays on the element in `body_html`. The stylesheet rule that gives `bg-o-color-N` its color is declared with `!important`. When the website palette is later rebuilt (any change to the primary colors), the new `bg-o-color-N` rule wins over the inline color whenever `body_html` is rendered. So an already-sent mailing reopened in the backend shows the new palette's color instead of the one that was picked, and resaving the mailing bakes that new color into `body_html`. `classToStyle` already does the right thing for the property value. What was missing is dropping the class itself from `body_html` once its style has been inlined, so no future `!important` palette rule can override the inline color. `body_arch` keeps the class, so the editor preview stays theme-aware while editing, but `body_html` is now stable across palette rebuilds. Steps to reproduce: 1. Open Email Marketing and create a new mailing using the Welcome Message template 2. Select a content block, open Customize, set the background to the 5th theme color 3. Save the mailing 4. Open the Website editor and change the 5th primary color to a different value 5. Reopen the saved mailing in the backend => the block's rendered background follows the new website color instead of the one picked at design time Ticket [link](https://www.odoo.com/odoo/project.task/5892350) opw-5892350 closes odoo#268001 X-original-commit: 880fe06 Signed-off-by: Damien Abeloos (abd) <abd@odoo.com> Signed-off-by: Mohamed Jemai (mojem) <mojem@odoo.com>
1 parent 1a1b223 commit 39742e3

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

addons/mail/static/src/views/web/fields/html_mail_field/convert_inline.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const RE_PADDING_MATCH = /[ ]*padding[^;]*;/g;
4343
const RE_PADDING = /([\d.]+)/;
4444
const RE_WHITESPACE = /[\s\u200b]*/;
4545
const SELECTORS_IGNORE = /(^\*$|:hover|:before|:after|:active|:link|::|')|@page/; // :not(:has) should be legal
46+
const RE_THEME_COLOR_CLASS = /^bg-o-color-\d+$/;
4647
const CONVERT_INLINE_BLACKLIST_CLASSES = ["o_mail_redirect"];
4748
// CSS properties relating to font, which Outlook seem to have trouble inheriting.
4849
const FONT_PROPERTIES_TO_INHERIT = [
@@ -569,6 +570,18 @@ export function classToStyle(element, cssRules) {
569570
});
570571
}
571572

573+
const themeColorClasses = [...node.classList].filter((c) => RE_THEME_COLOR_CLASS.test(c));
574+
if (themeColorClasses.length) {
575+
writes.push(() => {
576+
for (const cls of themeColorClasses) {
577+
node.classList.remove(cls);
578+
}
579+
if (!node.classList.length) {
580+
node.removeAttribute("class");
581+
}
582+
});
583+
}
584+
572585
if (node.nodeName === "IMG") {
573586
writes.push(() => {
574587
// Media list images should not have an inline height

addons/mail/static/tests/inline/convert_inline.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,23 @@ describe("Convert classes to inline styles", () => {
888888
styleSheet.deleteRule(0);
889889
});
890890

891+
test("strip theme color classes after inlining their styles", async () => {
892+
const bgColor = "rgb(17, 24, 39)";
893+
const style = document.createElement("style");
894+
style.textContent = `.bg-o-color-5 { background-color: ${bgColor} !important; }`;
895+
const fixture = getFixture();
896+
fixture.append(style);
897+
898+
editable.innerHTML = `<div class="bg-o-color-5 keep-me">Hello</div>`;
899+
fixture.append(editable);
900+
901+
classToStyle(editable, getCSSRules(editable.ownerDocument));
902+
903+
const block = editable.querySelector(".keep-me");
904+
expect(block).toHaveStyle({ backgroundColor: bgColor });
905+
expect(block).not.toHaveClass("bg-o-color-5");
906+
});
907+
891908
test("simplify border/margin/padding styles", async () => {
892909
// border-radius
893910
styleSheet.insertRule(

0 commit comments

Comments
 (0)