mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
Add parent checking before inserting or removing the child
This commit is contained in:
@@ -24,7 +24,9 @@ export default function DifyChatbot() {
|
||||
return () => {
|
||||
// 在组件卸载时清理 script 标签
|
||||
const existingScript = document.getElementById(siteConfig('DIFY_CHATBOT_TOKEN')); // 注意调用 siteConfig()
|
||||
if (existingScript) document.body.removeChild(existingScript);
|
||||
if (existingScript && existingScript.parentNode && existingScript.parentNode.contains(existingScript)) {
|
||||
existingScript.parentNode.removeChild(existingScript);
|
||||
}
|
||||
};
|
||||
}, []); // 注意依赖数组为空,意味着脚本将仅在加载页面时执行一次
|
||||
|
||||
|
||||
Reference in New Issue
Block a user