Jelajahi Sumber

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

Johan Ahlen 6 tahun lalu
induk
melakukan
87ee9fb9d7
1 mengubah file dengan 10 tambahan dan 1 penghapusan
  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()) {