瀏覽代碼

HUE-9082 [frontend] Prevent the same app from initializing twice

Johan Ahlen 6 年之前
父節點
當前提交
87ee9fb9d7
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. 10 1
      desktop/core/src/desktop/js/onePageViewModel.js

+ 10 - 1
desktop/core/src/desktop/js/onePageViewModel.js

@@ -261,7 +261,16 @@ class OnePageViewModel {
       });
     });
 
-    self.loadApp = function(app, loadDeep) {
+    let loadAppTimeout = -1;
+    self.loadApp = (app, loadDeep) => {
+      // This prevents loading an app twice when the URL is changed multiple times in one operation
+      window.clearTimeout(loadAppTimeout);
+      loadAppTimeout = window.setTimeout(() => {
+        self.loadAppThrottled(app, loadDeep);
+      }, 0);
+    };
+
+    self.loadAppThrottled = (app, loadDeep) => {
       if (self.currentApp() === 'editor' && $('#editorComponents').length) {
         const vm = ko.dataFor($('#editorComponents')[0]);
         if (vm.isPresentationMode()) {