From 0e73a5308a4267049189ed6e4dc48910c6c8ce80 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Wed, 26 Oct 2022 09:36:29 +0000 Subject: [PATCH] [FIX] website: invalidate snippet cache when changing language Commit [1] added a snippet template cache so that if a user changes pages on their website, they do not need to fetch the SnippetMenu from the server again. Unfortunately that commit added a few side effects that commit [2] tried to fix since commit [3] made them apparent. However, there is still one broken flow: - Create a website with 2 languages, e.g. English (primary) and French. - Visit the website in French and enable translate mode - Save and click on the "Edit in Master" button - Drag and drop a Snippet - The Snippet is in the translated language This commit fixes this broken flow by clearing the snippet cache when changing the language of the website. [1]: https://github.com/odoo/odoo/commit/03c552690b15cbf2e7d6b7812386ac64042219af#diff-52a4f9d2c217548e69e6b7fd097f286f1754a6389734eea254b87255e501cbefR18 [2]: https://github.com/odoo/odoo/commit/bb503962a36f3798c50049f2844e7b288b632955 [3]: https://github.com/odoo/odoo/commit/55a978aa86967581956f855a1c5db33b7425bd15 task-2687506 X-original-commit: eb214e1feb677c5061f9c034f3c4421a2109af2f Part-of: odoo/odoo#108643 --- .../src/client_actions/website_preview/website_preview.js | 3 +-- addons/website/static/src/services/website_service.js | 6 +++++- addons/website/static/src/systray_items/edit_website.js | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index c7d4b675760..b965a5c5211 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -365,10 +365,9 @@ export class WebsitePreview extends Component { const destinationUrl = new URL(href, window.location); destinationUrl.searchParams.delete('edit_translations'); destinationUrl.hash = this.websiteService.contentWindow.location.hash; - const forceLangUrl = `/website/lang/${lang}?r=${destinationUrl.toString()}`; this.websiteService.bus.trigger('LEAVE-EDIT-MODE', { onLeave: () => { - this.websiteService.goToWebsite({ path: forceLangUrl }); + this.websiteService.goToWebsite({ path: destinationUrl.toString(), lang }); }, reloadIframe: false, }); diff --git a/addons/website/static/src/services/website_service.js b/addons/website/static/src/services/website_service.js index 904c6e9faad..aadfbe23f5d 100644 --- a/addons/website/static/src/services/website_service.js +++ b/addons/website/static/src/services/website_service.js @@ -189,7 +189,11 @@ export const websiteService = { invalidateSnippetCache = value; }, - goToWebsite({ websiteId, path, edition, translation } = {}) { + goToWebsite({ websiteId, path, edition, translation, lang } = {}) { + if (lang) { + invalidateSnippetCache = true; + path = `/website/lang/${lang}?r=${encodeURIComponent(path)}`; + } action.doAction('website.website_preview', { clearBreadcrumbs: true, additionalContext: { diff --git a/addons/website/static/src/systray_items/edit_website.js b/addons/website/static/src/systray_items/edit_website.js index 8f44b72728d..79dc67469bd 100644 --- a/addons/website/static/src/systray_items/edit_website.js +++ b/addons/website/static/src/systray_items/edit_website.js @@ -47,7 +47,8 @@ class EditWebsiteSystray extends Component { const languagePrefix = `${pathname}/`.indexOf('/', 1); const defaultLanguagePathname = pathname.substring(languagePrefix); this.websiteService.goToWebsite({ - path: `/website/lang/default?r=${encodeURIComponent(defaultLanguagePathname + search + hash)}`, + path: defaultLanguagePathname + search + hash, + lang: 'default', edition: true }); } else {