fix: delete DocsAPI global + reload script on close for fresh ONLYOFFICE state

This commit is contained in:
root
2026-07-17 08:59:59 +00:00
parent a962f29f55
commit 163efd7a35
4 changed files with 25 additions and 14 deletions

View File

@@ -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-16T18:59:36.503Z" "updatedAt": "2026-07-17T08:58:13.712Z"
} }
] ]

View File

@@ -267,13 +267,24 @@ function forceSaveOnlyoffice() {
} }
} }
// Close the editor — standard ONLYOFFICE teardown // Close the editor — full teardown so the next open is completely fresh
function closeOnlyofficeEditor() { function closeOnlyofficeEditor() {
if (onlyofficeEditorInstance) { if (onlyofficeEditorInstance) {
try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {} try { onlyofficeEditorInstance.destroyEditor(); } catch (e) {}
onlyofficeEditorInstance = null; onlyofficeEditorInstance = null;
} }
closeModal(); closeModal();
// 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();
loadOnlyofficeTemplates(); loadOnlyofficeTemplates();
} }
@@ -305,16 +316,16 @@ async function openOnlyofficeEditor(templateId, templateName) {
`; `;
showModal(body, '', 'xlarge'); showModal(body, '', 'xlarge');
// Load ONLYOFFICE API script (once) // Load ONLYOFFICE API script fresh each time with cache-buster.
if (typeof DocsAPI === 'undefined') { // This ensures a completely new DocsAPI instance with no stale state.
await new Promise((resolve, reject) => { const scriptUrl = onlyofficeUrl + '/web-apps/apps/api/documents/api.js?cb=' + Date.now();
const s = document.createElement('script'); await new Promise((resolve, reject) => {
s.src = onlyofficeUrl + '/web-apps/apps/api/documents/api.js'; const s = document.createElement('script');
s.onload = resolve; s.src = scriptUrl;
s.onerror = () => reject(new Error('Failed to load ONLYOFFICE API')); s.onload = resolve;
document.head.appendChild(s); s.onerror = () => reject(new Error('Failed to load ONLYOFFICE API'));
}); document.head.appendChild(s);
} });
if (typeof DocsAPI === 'undefined' || !DocsAPI.DocEditor) { if (typeof DocsAPI === 'undefined' || !DocsAPI.DocEditor) {
throw new Error('ONLYOFFICE API not loaded'); throw new Error('ONLYOFFICE API not loaded');

View File

@@ -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=11"></script> <script src="/static/app.js?v=12"></script>
<script src="/static/carbone.js?v=11"></script> <script src="/static/carbone.js?v=12"></script>
</body> </body>
</html> </html>