Sfoglia il codice sorgente

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

Johan Ahlen 6 anni fa
parent
commit
87ee9fb9d7
1 ha cambiato i file con 10 aggiunte e 1 eliminazioni
  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()) {