fix: wait 2s after destroyEditor for ONLYOFFICE session to close before reopening
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,6 @@
|
|||||||
"originalName": "master_cv_template.docx",
|
"originalName": "master_cv_template.docx",
|
||||||
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
||||||
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
||||||
"updatedAt": "2026-07-17T08:58:13.712Z"
|
"updatedAt": "2026-07-17T09:01:35.526Z"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -277,10 +277,6 @@ function closeOnlyofficeEditor() {
|
|||||||
|
|
||||||
// Delete the DocsAPI global and remove the script tag so the next
|
// Delete the DocsAPI global and remove the script tag so the next
|
||||||
// openOnlyofficeEditor call loads a completely fresh ONLYOFFICE API.
|
// 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;
|
delete window.DocsAPI;
|
||||||
const oldScript = document.querySelector('script[src*="api/documents/api.js"]');
|
const oldScript = document.querySelector('script[src*="api/documents/api.js"]');
|
||||||
if (oldScript) oldScript.remove();
|
if (oldScript) oldScript.remove();
|
||||||
@@ -290,9 +286,14 @@ function closeOnlyofficeEditor() {
|
|||||||
|
|
||||||
// Open ONLYOFFICE editor in a modal
|
// Open ONLYOFFICE editor in a modal
|
||||||
async function openOnlyofficeEditor(templateId, templateName) {
|
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) {
|
if (onlyofficeEditorInstance) {
|
||||||
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
|
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
|
||||||
onlyofficeEditorInstance = null;
|
onlyofficeEditorInstance = null;
|
||||||
|
// Give ONLYOFFICE's internal session 2 seconds to fully close
|
||||||
|
await new Promise(r => setTimeout(r, 2000));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -317,7 +318,6 @@ async function openOnlyofficeEditor(templateId, templateName) {
|
|||||||
showModal(body, '', 'xlarge');
|
showModal(body, '', 'xlarge');
|
||||||
|
|
||||||
// Load ONLYOFFICE API script fresh each time with cache-buster.
|
// 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();
|
const scriptUrl = onlyofficeUrl + '/web-apps/apps/api/documents/api.js?cb=' + Date.now();
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const s = document.createElement('script');
|
const s = document.createElement('script');
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
<!-- Modals -->
|
<!-- Modals -->
|
||||||
<div class="modal-overlay" id="modal-overlay"></div>
|
<div class="modal-overlay" id="modal-overlay"></div>
|
||||||
|
|
||||||
<script src="/static/app.js?v=12"></script>
|
<script src="/static/app.js?v=13"></script>
|
||||||
<script src="/static/carbone.js?v=12"></script>
|
<script src="/static/carbone.js?v=13"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user