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

Commit 782895d

Browse files
authored
fix: When ce is used multiple times, subcomponents can hang on the style (#60)
1 parent 1528cf1 commit 782895d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

packages/sub-style/src/inject/inject-api-custom-element.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ const injectBindFnContent
1414
= 'instance.addCEChildStyle = this._addChildStyles.bind(this);\n'
1515
+ ' instance.removeCEChildStyle = this._removeChildStyles.bind(this);\n '
1616

17-
const injectAddAndRemoveStyle = ' _addChildStyles(styles, instance) {\n'
17+
const injectAddAndRemoveStyle = '_addChildStyles(styles, instance) {\n'
1818
+ ' if (styles) {\n'
1919
+ ' const styleContent = styles.join();\n'
20-
+ ' let cecStyle = /* @__PURE__ */ new Set();\n'
20+
// eslint-disable-next-line no-template-curly-in-string
21+
+ ' const ceKey = `__${this._instance.uid}`;\n'
22+
+ ' let ceKeySet = /* @__PURE__ */ new Set();\n'
2123
+ ' if (ceChildStyleMap.has(styleContent)) {\n'
22-
+ ' cecStyle = ceChildStyleMap.get(styleContent);\n'
23-
+ ' cecStyle.add(instance.uid);\n'
24-
+ ' ceChildStyleMap.set(styleContent, cecStyle);\n'
25-
+ ' return;\n'
24+
+ ' ceKeySet = ceChildStyleMap.get(styleContent);\n'
25+
+ ' if (ceKeySet.has(ceKey)) {\n'
26+
+ ' ceKeySet.add(ceKey);\n'
27+
+ ' ceChildStyleMap.set(styleContent, ceKeySet);\n'
28+
+ ' return;\n'
29+
+ ' }\n'
2630
+ ' }\n'
27-
+ ' cecStyle.add(instance.uid);\n'
28-
+ ' ceChildStyleMap.set(styleContent, cecStyle);\n'
31+
+ ' ceKeySet.add(ceKey);\n'
32+
+ ' ceChildStyleMap.set(styleContent, ceKeySet);\n'
2933
// eslint-disable-next-line no-template-curly-in-string
3034
+ ' const ceStyleId = `data-v-ce-${instance.uid}`;\n'
3135
+ ' styles.forEach((css, index) => {\n'
@@ -52,8 +56,10 @@ const injectAddAndRemoveStyle = ' _addChildStyles(styles, instance) {\n'
5256
+ ' const styleContent = styles.join();\n'
5357
+ ' let cecStyle = /* @__PURE__ */ new Set();\n'
5458
+ ' if (ceChildStyleMap.has(styleContent)) {\n'
59+
// eslint-disable-next-line no-template-curly-in-string
60+
+ ' const ceKey = `__${this._instance.uid}`;\n'
5561
+ ' cecStyle = ceChildStyleMap.get(styleContent);\n'
56-
+ ' cecStyle.delete(uid);\n'
62+
+ ' cecStyle.delete(ceKey);\n'
5763
+ ' if (cecStyle.size === 0) {\n'
5864
// eslint-disable-next-line no-template-curly-in-string
5965
+ ' const sList = this.shadowRoot.querySelectorAll(`[data-v-ce-${uid}]`);\n'

0 commit comments

Comments
 (0)