From 6e8f8410d4de7da667bd8c4e335484cb8d1a7f20 Mon Sep 17 00:00:00 2001 From: josc146 Date: Thu, 16 Mar 2023 09:31:15 +0800 Subject: [PATCH] fix: repeat rendering (#3) --- src/content-script/index.jsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index 0c9be19..25b1030 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -1,4 +1,5 @@ import './styles.scss' +import { unmountComponentAtNode } from 'react-dom' import { render } from 'preact' import DecisionCard from '../components/DecisionCard' import { config as siteConfig } from './site-adapters' @@ -27,13 +28,19 @@ async function mountComponent(siteConfig, userConfig) { ) return - document.querySelectorAll('.chat-gpt-container').forEach((e) => e.remove()) + document.querySelectorAll('.chat-gpt-container').forEach((e) => { + unmountComponentAtNode(e) + e.remove() + }) let question if (userConfig.inputQuery) question = await getInput([userConfig.inputQuery]) if (!question && siteConfig) question = await getInput(siteConfig.inputQuery) - document.querySelectorAll('.chat-gpt-container').forEach((e) => e.remove()) + document.querySelectorAll('.chat-gpt-container').forEach((e) => { + unmountComponentAtNode(e) + e.remove() + }) const container = document.createElement('div') container.className = 'chat-gpt-container' render(