Skip to content

Commit

Permalink
fix: clear memoized style chain cache
Browse files Browse the repository at this point in the history
  • Loading branch information
joshhowenstine committed Nov 28, 2023
1 parent fc00991 commit 1a5c576
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import {
generateComponentStyleSource,
getStyleChainMemoized,
clearStyleChainCache,
generateStyle,
getHash
} from './utils.js';
Expand Down Expand Up @@ -93,6 +94,7 @@ export default class StyleManager extends lng.EventEmitter {
* @private
*/
_onThemeUpdate() {
clearStyleChainCache()

Check failure on line 97 in packages/@lightningjs/ui-components/src/mixins/withThemeStyles/StyleManager.js

View workflow job for this annotation

GitHub Actions / quality / lint-unit

Insert `;`
this.clearSourceCache();
this.clearStyleCache();
this.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,18 @@ export function generateNameFromPrototypeChain(obj, name = '') {
*/
const styleChainCache = {};

/**
* Flush the memoization cache for styleChain
*
*/
export const clearStyleChainCache = () => {
for (const key in styleChainCache) {
if (styleChainCache.hasOwnProperty(key)) {
delete styleChainCache[key];
}
}
};

/**
* Memoized version of getStyleChain function. Retrieves the style chain for a component by traversing its prototype chain.
* @param {object} componentObj - The component object to get the style chain from.
Expand Down Expand Up @@ -659,7 +671,6 @@ export const getStyleChain = componentObj => {
) {
// ComponentConfig Level
const { style: componentConfigStyle } = getComponentConfig(proto);

if (Object.keys(componentConfigStyle || {}).length) {
if (!styleMap.has(componentConfigStyle)) {
styleMap.set(componentConfigStyle, { style: componentConfigStyle });
Expand Down

0 comments on commit 1a5c576

Please sign in to comment.