diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-12-17 11:11:30 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-12-17 11:11:30 +0000 |
| commit | cc531a07002fd8642f53e77c0fa52a49753e9df8 (patch) | |
| tree | 5fcf24508b2ab5436a4f24f6b1d305292d5474a2 /addons/mail/static/src/components/message | |
| parent | b6b5e7c148f2b7b44830022325aa9010a4c683ba (diff) | |
[FIX] mail: speed up render of Message by inserting content manually
`t-raw` is too slow due to parsing the HTML in JS, converting it to VDOM and
comparing to existing VDOM. Here we can make a custom comparison based on actual
string, and directly replace in DOM if needed.
Part of task-2399731
closes odoo/odoo#63505
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components/message')
| -rw-r--r-- | addons/mail/static/src/components/message/message.js | 14 | ||||
| -rw-r--r-- | addons/mail/static/src/components/message/message.xml | 2 | ||||
| -rw-r--r-- | addons/mail/static/src/components/message/message_tests.js | 2 |
3 files changed, 16 insertions, 2 deletions
diff --git a/addons/mail/static/src/components/message/message.js b/addons/mail/static/src/components/message/message.js index 7423b1443fb..7fc8a1f050a 100644 --- a/addons/mail/static/src/components/message/message.js +++ b/addons/mail/static/src/components/message/message.js @@ -81,6 +81,16 @@ class Message extends Component { */ this._wasSelected; /** + * Value of the last rendered prettyBody. Useful to compare to new value + * to decide if it has to be updated. + */ + this._lastPrettyBody; + /** + * Reference to element containing the prettyBody. Useful to be able to + * replace prettyBody with new value in JS (which is faster than t-raw). + */ + this._prettyBodyRef = useRef('prettyBody'); + /** * Reference to the content of the message. */ this._contentRef = useRef('content'); @@ -371,6 +381,10 @@ class Message extends Component { if (!this.message) { return; } + if (this._prettyBodyRef.el && this.message.prettyBody !== this._lastPrettyBody) { + this._prettyBodyRef.el.innerHTML = this.message.prettyBody; + this._lastPrettyBody = this.message.prettyBody; + } // Remove all readmore before if any before reinsert them with _insertReadMoreLess. // This is needed because _insertReadMoreLess is working with direct DOM mutations // which are not sync with Owl. diff --git a/addons/mail/static/src/components/message/message.xml b/addons/mail/static/src/components/message/message.xml index 9207dab2485..476b6f156f4 100644 --- a/addons/mail/static/src/components/message/message.xml +++ b/addons/mail/static/src/components/message/message.xml @@ -156,7 +156,7 @@ </t> </t> <div class="o_Message_content" t-ref="content"> - <t t-raw="message.prettyBody"/> + <div class="o_Message_prettyBody" t-ref="prettyBody"/><!-- message.prettyBody is inserted here from _update() --> <t t-if="message.subtype_description and !message.isBodyEqualSubtypeDescription"> <p t-esc="message.subtype_description"/> </t> diff --git a/addons/mail/static/src/components/message/message_tests.js b/addons/mail/static/src/components/message/message_tests.js index 15c070ccde1..99c74dc0604 100644 --- a/addons/mail/static/src/components/message/message_tests.js +++ b/addons/mail/static/src/components/message/message_tests.js @@ -111,7 +111,7 @@ QUnit.test('basic rendering', async function (assert) { "message should display the content" ); assert.strictEqual( - messageEl.querySelector(`:scope .o_Message_content`).innerHTML, + messageEl.querySelector(`:scope .o_Message_prettyBody`).innerHTML, "<p>Test</p>", "message should display the correct content" ); |
