fix: wait 2s after destroyEditor for ONLYOFFICE session to close before reopening
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user