From 01713fb1ab2e6032a7ee7503b5849d72aafb856f Mon Sep 17 00:00:00 2001 From: YannisJustine Date: Thu, 28 Nov 2024 22:07:42 +0100 Subject: [PATCH] fix: restore original unmounted implementation in BaseComponent --- .../core/src/basecomponent/BaseComponent.vue | 3 ++- .../core/src/basedirective/BaseDirective.js | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/core/src/basecomponent/BaseComponent.vue b/packages/core/src/basecomponent/BaseComponent.vue index cd9561f9a..1f308debe 100644 --- a/packages/core/src/basecomponent/BaseComponent.vue +++ b/packages/core/src/basecomponent/BaseComponent.vue @@ -53,7 +53,7 @@ export default { if (newValue) { this._loadScopedThemeStyles(newValue); this._themeScopedListener = () => this._loadScopedThemeStyles(newValue); - this._themeChangeListener(this._themeScopedListener) + this._themeChangeListener(this._themeScopedListener); } else { this._unloadScopedThemeStyles(); } @@ -107,6 +107,7 @@ export default { unmounted() { ThemeService.off('theme:change', this._loadCoreStyles); ThemeService.off('theme:change', this._load); + this._unloadScopedThemeStyles(); this._hook('onUnmounted'); }, methods: { diff --git a/packages/core/src/basedirective/BaseDirective.js b/packages/core/src/basedirective/BaseDirective.js index 95aa1283b..de20ca98a 100644 --- a/packages/core/src/basedirective/BaseDirective.js +++ b/packages/core/src/basedirective/BaseDirective.js @@ -79,7 +79,7 @@ const BaseDirective = { BaseDirective._loadThemeStyles(el.$instance, useStyleOptions); BaseDirective._loadScopedThemeStyles(el.$instance, useStyleOptions); - const loadStyle = () => BaseDirective._loadThemeStyles(el.$instance, useStyleOptions) + const loadStyle = () => BaseDirective._loadThemeStyles(el.$instance, useStyleOptions); BaseDirective._themeChangeListener(el.$instance, loadStyle); }, @@ -137,7 +137,7 @@ const BaseDirective = { }, _themeChangeListener(instance, callback = () => {}) { if (!instance || !callback) return; - + // Store callback reference let listeners = _themesCallback.get(instance.$attrSelector); @@ -155,7 +155,7 @@ const BaseDirective = { const listeners = _themesCallback.get(instance.$attrSelector); if (listeners) { - listeners.forEach(callback => { + listeners.forEach((callback) => { ThemeService.off('theme:change', callback); }); listeners.clear(); @@ -221,11 +221,10 @@ const BaseDirective = { const handleWatch = (el) => { const watchers = el.$instance?.watch; - const handleWatchConfig = ({ newValue, oldValue }) => watchers?.['config']?.call(el.$instance, newValue, oldValue); - const handleWatchConfigRipple = ({ newValue, oldValue }) => watchers?.['config.ripple']?.call(el.$instance, newValue, oldValue) + const handleWatchConfigRipple = ({ newValue, oldValue }) => watchers?.['config.ripple']?.call(el.$instance, newValue, oldValue); - _configCallback.set(el, { config: handleWatchConfig, 'config.ripple': handleWatchConfigRipple }); + _configCallback.set(el.$instance.$attrSelector, { config: handleWatchConfig, 'config.ripple': handleWatchConfigRipple }); // for 'config' watchers?.['config']?.call(el.$instance, el.$instance?.$primevueConfig); @@ -237,14 +236,14 @@ const BaseDirective = { }; const removeWatch = (el) => { - const watchers = _configCallback.get(el); + const watchers = _configCallback.get(el.$instance.$attrSelector); if (watchers) { PrimeVueService.off('config:change', watchers.config); PrimeVueService.off('config:ripple:change', watchers['config.ripple']); - _configCallback.delete(el); + _configCallback.delete(el.$instance.$attrSelector); } - } + }; return { created: (el, binding, vnode, prevVnode) => {