Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix: When ce is used multiple times, subcomponents can hang on the st…
Browse files Browse the repository at this point in the history
…yle (#60)
  • Loading branch information
baiwusanyu-c authored Aug 9, 2023
1 parent 1528cf1 commit 782895d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/sub-style/src/inject/inject-api-custom-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ const injectBindFnContent
= 'instance.addCEChildStyle = this._addChildStyles.bind(this);\n'
+ ' instance.removeCEChildStyle = this._removeChildStyles.bind(this);\n '

const injectAddAndRemoveStyle = ' _addChildStyles(styles, instance) {\n'
const injectAddAndRemoveStyle = '_addChildStyles(styles, instance) {\n'
+ ' if (styles) {\n'
+ ' const styleContent = styles.join();\n'
+ ' let cecStyle = /* @__PURE__ */ new Set();\n'
// eslint-disable-next-line no-template-curly-in-string
+ ' const ceKey = `__${this._instance.uid}`;\n'
+ ' let ceKeySet = /* @__PURE__ */ new Set();\n'
+ ' if (ceChildStyleMap.has(styleContent)) {\n'
+ ' cecStyle = ceChildStyleMap.get(styleContent);\n'
+ ' cecStyle.add(instance.uid);\n'
+ ' ceChildStyleMap.set(styleContent, cecStyle);\n'
+ ' return;\n'
+ ' ceKeySet = ceChildStyleMap.get(styleContent);\n'
+ ' if (ceKeySet.has(ceKey)) {\n'
+ ' ceKeySet.add(ceKey);\n'
+ ' ceChildStyleMap.set(styleContent, ceKeySet);\n'
+ ' return;\n'
+ ' }\n'
+ ' }\n'
+ ' cecStyle.add(instance.uid);\n'
+ ' ceChildStyleMap.set(styleContent, cecStyle);\n'
+ ' ceKeySet.add(ceKey);\n'
+ ' ceChildStyleMap.set(styleContent, ceKeySet);\n'
// eslint-disable-next-line no-template-curly-in-string
+ ' const ceStyleId = `data-v-ce-${instance.uid}`;\n'
+ ' styles.forEach((css, index) => {\n'
Expand All @@ -52,8 +56,10 @@ const injectAddAndRemoveStyle = ' _addChildStyles(styles, instance) {\n'
+ ' const styleContent = styles.join();\n'
+ ' let cecStyle = /* @__PURE__ */ new Set();\n'
+ ' if (ceChildStyleMap.has(styleContent)) {\n'
// eslint-disable-next-line no-template-curly-in-string
+ ' const ceKey = `__${this._instance.uid}`;\n'
+ ' cecStyle = ceChildStyleMap.get(styleContent);\n'
+ ' cecStyle.delete(uid);\n'
+ ' cecStyle.delete(ceKey);\n'
+ ' if (cecStyle.size === 0) {\n'
// eslint-disable-next-line no-template-curly-in-string
+ ' const sList = this.shadowRoot.querySelectorAll(`[data-v-ce-${uid}]`);\n'
Expand Down

0 comments on commit 782895d

Please sign in to comment.