From 5b37c3d694bb7434b0950add67740334f3cda549 Mon Sep 17 00:00:00 2001 From: Thijs Louisse Date: Tue, 29 Oct 2024 11:40:23 +0100 Subject: [PATCH] fix(ui/localize.js): make LocalizeManager ssr-compatible --- .changeset/olive-eagles-glow.md | 5 +++ .../localize/src/LocalizeManager.js | 31 ++----------------- 2 files changed, 8 insertions(+), 28 deletions(-) create mode 100644 .changeset/olive-eagles-glow.md diff --git a/.changeset/olive-eagles-glow.md b/.changeset/olive-eagles-glow.md new file mode 100644 index 0000000000..382e4e82c1 --- /dev/null +++ b/.changeset/olive-eagles-glow.md @@ -0,0 +1,5 @@ +--- +'@lion/ui': patch +--- + +[localize] make LocalizeManager ssr-compatible diff --git a/packages/ui/components/localize/src/LocalizeManager.js b/packages/ui/components/localize/src/LocalizeManager.js index 43dd398147..8b75d9c74a 100644 --- a/packages/ui/components/localize/src/LocalizeManager.js +++ b/packages/ui/components/localize/src/LocalizeManager.js @@ -12,7 +12,7 @@ import isLocalizeESModule from './isLocalizeESModule.js'; /** * `LocalizeManager` manages your translations (includes loading) */ -export class LocalizeManager { +export class LocalizeManager extends EventTarget { // eslint-disable-line no-unused-vars constructor({ autoLoadOnLocaleChange = false, @@ -20,8 +20,8 @@ export class LocalizeManager { showKeyAsFallback = false, allowOverridesForExistingNamespaces = false, } = {}) { - /** @private */ - this.__delegationTarget = document.createDocumentFragment(); + super(); + /** @protected */ this._autoLoadOnLocaleChange = !!autoLoadOnLocaleChange; /** @protected */ @@ -480,31 +480,6 @@ export class LocalizeManager { return locale.substring(0, 2); } - /** - * @param {string} type - * @param {EventListener} listener - * @param {...Object} options - */ - addEventListener(type, listener, ...options) { - this.__delegationTarget.addEventListener(type, listener, ...options); - } - - /** - * @param {string} type - * @param {EventListener} listener - * @param {...Object} options - */ - removeEventListener(type, listener, ...options) { - this.__delegationTarget.removeEventListener(type, listener, ...options); - } - - /** - * @param {CustomEvent} event - */ - dispatchEvent(event) { - this.__delegationTarget.dispatchEvent(event); - } - /** * @param {string} newLocale * @param {string} oldLocale