mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 18:41:52 +08:00
fix(editor): shadowless element should remove style element correctly (#10128)
[BS-2565](https://linear.app/affine-design/issue/BS-2565/关闭-chat-block-center-peek-后新生成的-chat-block-最后一个-message-样式不正确)
This commit is contained in:
@@ -12,7 +12,7 @@ export class ShadowlessElement extends LitElement {
|
|||||||
|
|
||||||
static onDisconnectedMap = new WeakMap<
|
static onDisconnectedMap = new WeakMap<
|
||||||
Constructor, // class
|
Constructor, // class
|
||||||
(() => void) | null
|
WeakMap<Node, (() => void) | null>
|
||||||
>();
|
>();
|
||||||
|
|
||||||
// styles registered in ShadowlessElement will be available globally
|
// styles registered in ShadowlessElement will be available globally
|
||||||
@@ -67,7 +67,10 @@ export class ShadowlessElement extends LitElement {
|
|||||||
injectedStyles.push(style);
|
injectedStyles.push(style);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
SE.onDisconnectedMap.set(SE, () => {
|
if (!SE.onDisconnectedMap.has(SE)) {
|
||||||
|
SE.onDisconnectedMap.set(SE, new WeakMap());
|
||||||
|
}
|
||||||
|
SE.onDisconnectedMap.get(SE)?.set(parentRoot, () => {
|
||||||
injectedStyles.forEach(style => style.remove());
|
injectedStyles.forEach(style => style.remove());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -79,6 +82,7 @@ export class ShadowlessElement extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override disconnectedCallback(): void {
|
override disconnectedCallback(): void {
|
||||||
|
const parentRoot = this.getRootNode();
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
const SE = this.constructor as typeof ShadowlessElement;
|
const SE = this.constructor as typeof ShadowlessElement;
|
||||||
let styleInjectedCount = this.getConnectedCount();
|
let styleInjectedCount = this.getConnectedCount();
|
||||||
@@ -86,7 +90,8 @@ export class ShadowlessElement extends LitElement {
|
|||||||
this.setConnectedCount(styleInjectedCount);
|
this.setConnectedCount(styleInjectedCount);
|
||||||
|
|
||||||
if (styleInjectedCount === 0) {
|
if (styleInjectedCount === 0) {
|
||||||
SE.onDisconnectedMap.get(SE)?.();
|
// remove the style element when the last shadowless element is disconnected in the parent root
|
||||||
|
SE.onDisconnectedMap.get(SE)?.get(parentRoot)?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user