From 7a6181e8c72cd110cdfc09f624f8be43e76ef74c Mon Sep 17 00:00:00 2001
From: vben <anncwb@126.com>
Date: Tue, 27 Oct 2020 21:53:53 +0800
Subject: [PATCH] fix: hmr multiple registered components

---
 CHANGELOG.zh_CN.md                 | 4 ++++
 src/App.vue                        | 2 +-
 src/components/registerGlobComp.ts | 5 +++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md
index 2f575c8..011408e 100644
--- a/CHANGELOG.zh_CN.md
+++ b/CHANGELOG.zh_CN.md
@@ -16,6 +16,10 @@
 
 - 独立出`vite-plugin-html`,并修改相关插入 html 的逻辑
 
+### 🐛 Bug Fixes
+
+- 修复热更新时多次注册组件警告问题
+
 ## 2.0.0-rc.5 (2020-10-26)
 
 ### ✨ Features
diff --git a/src/App.vue b/src/App.vue
index 92b6a48..1059d2b 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -20,7 +20,7 @@
   moment.locale('zh-cn');
 
   export default defineComponent({
-    name: 'App',
+    name: 'App1',
     components: { ConfigProvider },
     setup() {
       useInitAppConfigStore();
diff --git a/src/components/registerGlobComp.ts b/src/components/registerGlobComp.ts
index 15c2831..e0561e0 100644
--- a/src/components/registerGlobComp.ts
+++ b/src/components/registerGlobComp.ts
@@ -5,8 +5,13 @@ import { Button as AntButton } from 'ant-design-vue';
 import { getApp } from '/@/useApp';
 
 const compList = [Icon, BasicHelp, BasicTitle, Button, AntButton.Group];
+
+// Fix hmr multiple registered components
+let registered = false;
 export function registerGlobComp() {
+  if (registered) return;
   compList.forEach((comp: any) => {
     getApp().component(comp.name, comp);
   });
+  registered = true;
 }
--
libgit2 0.23.3