fix: wait 2s after destroyEditor for ONLYOFFICE session to close before reopening

This commit is contained in:
root
2026-07-17 09:03:52 +00:00
parent 163efd7a35
commit 680176f166
4 changed files with 8 additions and 8 deletions

View File

@@ -6,6 +6,6 @@
"originalName": "master_cv_template.docx",
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
"uploadedAt": "2026-07-16T09:03:29.601Z",
"updatedAt": "2026-07-17T08:58:13.712Z"
"updatedAt": "2026-07-17T09:01:35.526Z"
}
]

View File

@@ -277,10 +277,6 @@ function closeOnlyofficeEditor() {
// Delete the DocsAPI global and remove the script tag so the next
// openOnlyofficeEditor call loads a completely fresh ONLYOFFICE API.
// This is the key: destroyEditor() cleans the editor instance, but
// the DocsAPI object itself retains internal state (websocket pools,
// document session references) that causes the next editor to load
// a stale document. Removing the script + global forces a fresh init.
delete window.DocsAPI;
const oldScript = document.querySelector('script[src*="api/documents/api.js"]');
if (oldScript) oldScript.remove();
@@ -290,9 +286,14 @@ function closeOnlyofficeEditor() {
// Open ONLYOFFICE editor in a modal
async function openOnlyofficeEditor(templateId, templateName) {
// Block reopening if a previous editor is still tearing down.
// destroyEditor() is async — the ONLYOFFICE websocket/session needs
// time to close before a new editor can be created cleanly.
if (onlyofficeEditorInstance) {
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
onlyofficeEditorInstance = null;
// Give ONLYOFFICE's internal session 2 seconds to fully close
await new Promise(r => setTimeout(r, 2000));
}
try {
@@ -317,7 +318,6 @@ async function openOnlyofficeEditor(templateId, templateName) {
showModal(body, '', 'xlarge');
// Load ONLYOFFICE API script fresh each time with cache-buster.
// This ensures a completely new DocsAPI instance with no stale state.
const scriptUrl = onlyofficeUrl + '/web-apps/apps/api/documents/api.js?cb=' + Date.now();
await new Promise((resolve, reject) => {
const s = document.createElement('script');

View File

@@ -139,7 +139,7 @@
<!-- Modals -->
<div class="modal-overlay" id="modal-overlay"></div>
<script src="/static/app.js?v=12"></script>
<script src="/static/carbone.js?v=12"></script>
<script src="/static/app.js?v=13"></script>
<script src="/static/carbone.js?v=13"></script>
</body>
</html>