Bläddra i källkod

fix: editor/toolbar destroy 用 try-catch 兜住,避免半销毁 Slate 状态下冒未捕获异常

wangEditor 5 内部销毁链路中若 Slate proxy 已被 revoke(例如连续销毁、
keep-alive 复用 + 切 tab),destroy() 抛 "Cannot perform 'get' on a proxy
that has been revoked"。这类异常如果直接冒到 console,会污染日志并且
可能影响 Vue 渲染。try-catch 兜住,保证清理链路可以继续推进。
Developer 4 veckor sedan
förälder
incheckning
bd57389d66
2 ändrade filer med 7 tillägg och 2 borttagningar
  1. BIN
      dist.zip
  2. 7 2
      src/components/editor/index.vue

BIN
dist.zip


+ 7 - 2
src/components/editor/index.vue

@@ -51,12 +51,17 @@ export default {
             }
         },
         _destroyEditor() {
+            // destroy() 在已 destroy 过 / 半销毁 Slate 状态下会抛 "proxy has been revoked"
+            // 之类的异常。Vue 2 中未捕获异常会沿调用栈冒到 console 报红,
+            // 但更糟的是 selectionchange 这种 document 监听器如果没及时
+            // removeEventListener,下次用户点页面会再次触发同一个错误循环。
+            // 用 try-catch 兜住,保证清理链路不会被打断。
             if (this.editor) {
-                this.editor.destroy()
+                try { this.editor.destroy() } catch (e) { /* swallow: half-destroyed slate */ }
                 this.editor = null
             }
             if (this.toolbar) {
-                this.toolbar.destroy()
+                try { this.toolbar.destroy() } catch (e) { /* swallow */ }
                 this.toolbar = null
             }
         },