[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
This commit is contained in:
Arthur Detroux (ard)
2022-12-23 21:19:50 +01:00
parent d816ef8939
commit 0e73a5308a
3 changed files with 8 additions and 4 deletions
@@ -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,
});
@@ -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: {
@@ -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 {