From c084533efb4bac37bb46472066ccbcfc052610e5 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Wed, 29 Jun 2016 21:45:42 +0530 Subject: [PATCH] Wait till page is rendered There's a race condition here between page being rendered with all the document(s) information and showing the editor to the user. The later requires the former as it uses data rendered into the page. In most cases, former is quick enough and we do not see any problems, but in some cases, mostly when the server is responding very slowly, it will lag behind the later causing the editor to be shown before data is rendered into the page leading to '404 Object not found'. This should, hopefully, avoid such cases. --- js/documents.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/documents.js b/js/documents.js index 66dc6722..ee578bc8 100644 --- a/js/documents.js +++ b/js/documents.js @@ -17,6 +17,7 @@ $.widget('oc.documentGrid', { jQuery.when(this._load(fileId)) .then(function(){ that._render(); + documentsMain.renderComplete = true; }); }, @@ -189,6 +190,7 @@ var documentsMain = { loadError : false, loadErrorMessage : '', loadErrorHint : '', + renderComplete: false, // false till page is rendered with all required data about the document(s) toolbar : '
', returnToDir : null, // directory where we started from in the 'Files' app @@ -375,6 +377,12 @@ var documentsMain = { return; } + if (!documentsMain.renderComplete) { + setTimeout(function() { documentsMain.UI.showEditor(title); }, 500); + console.log('Waiting for page to render ...'); + return; + } + $(document.body).addClass("claro"); $(document.body).prepend(documentsMain.UI.container);