From da9b81f28dbb3a67f4709c33bef64a189828dab7 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Tue, 23 Aug 2022 13:41:02 +0000 Subject: [PATCH] [FIX] website: fix snippet social media values cache This `s_social_media` snippet option uses a variable defined in the module's scope to store social media values. This reduces the amount of RPCs needed to fetch the data as they will only be done once per edition. Prior to commit [1], this cache would only exist as long as the page lived. Which means that switching website, switching page or going in the backend would reset its value. Commit [1] moved the edition in the backend which means that the cache would persist between pages but more importantly, between websites, only resetting if the backend was refreshed or left. Steps to reproduce: - Go on website 1 - Modify the URL for facebook in the footer - Go on website 2 - The value is the same when it should still be facebook.com/Odoo This commit fixes that by resetting the cache when the editor is destroyed. [1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b closes odoo/odoo#103689 X-original-commit: 3efb726575679f62f9ee2894193323bfe45d7938 Signed-off-by: Romain Derie (rde) --- addons/website/static/src/js/editor/wysiwyg.js | 10 ++++++++++ .../static/src/snippets/s_social_media/options.js | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/addons/website/static/src/js/editor/wysiwyg.js b/addons/website/static/src/js/editor/wysiwyg.js index c8ad83d76b4..cfc2664c133 100644 --- a/addons/website/static/src/js/editor/wysiwyg.js +++ b/addons/website/static/src/js/editor/wysiwyg.js @@ -3,6 +3,7 @@ odoo.define('website.wysiwyg', function (require) { var Wysiwyg = require('web_editor.wysiwyg'); var snippetsEditor = require('website.snippet.editor'); +let socialMediaOptions = require('@website/snippets/s_social_media/options')[Symbol.for("default")]; /** * Show/hide the dropdowns associated to the given toggles and allows to wait @@ -101,6 +102,15 @@ const WebsiteWysiwyg = Wysiwyg.extend({ * @override */ destroy: function () { + // We do not need the cache to live longer than the edition. + // Keeping it alive could end up in a corrupt state without the user + // even noticing. (If the values were changed in another tab or by + // someone else, when edit starts again here, without a clear cache at + // destroy, options will have wrong social media values). + // It would also survive (multi) website switch, not fetching the values + // from the accessed website. + socialMediaOptions.clearDbSocialValuesCache(); + this._restoreMegaMenus(); this._super.apply(this, arguments); }, diff --git a/addons/website/static/src/snippets/s_social_media/options.js b/addons/website/static/src/snippets/s_social_media/options.js index 2171112d8e4..88d4895401f 100644 --- a/addons/website/static/src/snippets/s_social_media/options.js +++ b/addons/website/static/src/snippets/s_social_media/options.js @@ -7,6 +7,10 @@ import {_t} from 'web.core'; let dbSocialValues; let dbSocialValuesProm; +const clearDbSocialValuesCache = () => { + dbSocialValuesProm = undefined; + dbSocialValues = undefined; +}; options.registry.SocialMedia = options.Class.extend({ /** @@ -351,4 +355,5 @@ options.registry.SocialMedia = options.Class.extend({ export default { SocialMedia: options.registry.SocialMedia, + clearDbSocialValuesCache, };