feat: show error hint when infinite loops exists in code
diff --git a/src/common/i18n.js b/src/common/i18n.js
index a5bc185..5a7d6a9 100644
--- a/src/common/i18n.js
+++ b/src/common/i18n.js
@@ -4,6 +4,7 @@
       run: 'Run',
       format: 'Format',
       errorInEditor: 'Errors exist in code!',
+      infiniteLoopInEditor: 'Potential infinite loops exist in code!',
       chartOK: 'Chart has been generated successfully, ',
 
       darkMode: 'Dark Mode',
@@ -92,6 +93,7 @@
       run: '运行',
       format: '格式化',
       errorInEditor: '编辑器内容有误!',
+      infiniteLoopInEditor: '编辑器内容可能存在无限循环!',
       chartOK: '图表已生成, ',
 
       darkMode: '深色模式',
diff --git a/src/editor/Preview.vue b/src/editor/Preview.vue
index f2ba8b2..063fec8 100644
--- a/src/editor/Preview.vue
+++ b/src/editor/Preview.vue
@@ -155,12 +155,12 @@
 const hasBMap = example && example.tags.indexOf('bmap') >= 0;
 
 function getScriptURL(link) {
-  return isDebug || isLocal ? link.replace('.min.', '') : link;
+  return isDebug || isLocal ? link.replace('.min.', '.') : link;
 }
 
 function getScripts(nightly) {
   const echartsDir = SCRIPT_URLS[
-    nightly && !isLocal ? 'echartsNightlyDir' : 'echartsDir'
+    isLocal ? 'localEChartsDir' : nightly ? 'echartsNightlyDir' : 'echartsDir'
   ].replace('{{version}}', store.echartsVersion);
 
   return [
@@ -221,8 +221,18 @@
         this.loading = false;
         this.dispose();
       },
-      () => {
-        log(this.$t('editor.errorInEditor'), 'error');
+      (errMsg) => {
+        console.log(errMsg);
+        const infiniteLoopInEditor =
+          errMsg && errMsg.indexOf('loop executes') > -1;
+        log(
+          this.$t(
+            `editor.${
+              infiniteLoopInEditor ? 'infiniteLoopInEditor' : 'errorInEditor'
+            }`
+          ),
+          'error'
+        );
       },
       (option, updateTime) => {
         if (
diff --git a/src/editor/sandbox/index.js b/src/editor/sandbox/index.js
index bd56eda..834143e 100644
--- a/src/editor/sandbox/index.js
+++ b/src/editor/sandbox/index.js
@@ -69,7 +69,7 @@
       //   onerror();
       //   break;
       case 'codeError':
-        onCodeError();
+        onCodeError(data.message);
         break;
       default:
         break;
diff --git a/src/editor/sandbox/setup.js b/src/editor/sandbox/setup.js
index c632696..54ec023 100644
--- a/src/editor/sandbox/setup.js
+++ b/src/editor/sandbox/setup.js
@@ -88,7 +88,7 @@
     },
 
     run({ store, recreateInstance }) {
-      if (!chartInstance || recreateInstance) {
+      if (recreateInstance || !chartInstance || chartInstance.isDisposed()) {
         this.dispose();
         window.chartInstance = chartInstance = echarts.init(
           document.getElementById('chart-container'),
@@ -172,7 +172,7 @@
         echarts.util.isObject(option) && chartInstance.setOption(option, true);
       } catch (e) {
         console.error('failed to run code', e);
-        sendMessage({ evt: 'codeError' });
+        sendMessage({ evt: 'codeError', message: e.message });
       }
 
       if (gui) {