nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.43k stars 4.07k forks source link

[Bug]: ONLYOFFICE Document Server: document is not opened in the ONLYOFFICE editor by default #49049

Open alexonlyoffice opened 1 week ago

alexonlyoffice commented 1 week ago

⚠️ This issue respects the following points: ⚠️

Bug description

Newly created file is not opened in the ONLYOFFICE editor by default, if the previously opened file was closed by Open file location button.

Checked on Nextcloud Hub 9 (30.0.1), ONLYOFFICE Connector 9.5.0, DS 8.2.0. Here is the video showing the case

https://github.com/user-attachments/assets/b62addc6-0355-419b-8961-ef5aac9d712e

This is how document creation is implemented in integration:

We implemented registerTemplateFileCreator.

On the client we have document creation registration registerFileAction.

During the first document creation exec method is fired and successful document opening follows. The issue is that after quitting the editor and repeated creating of the document in the same tab without page refreshing the exec method is not invoked.

Steps to reproduce

  1. Make sure Open file in the same tab checkbox is marked in the connector settings;
  2. Create a document in All files section -> editor will open;
  3. Leave the document by clicking on the Open file location button on the editor toolbar;
  4. Create a new document -> editor will not be opened, document appears in the file manager.

Expected behavior

Newly created file is opened in the ONLYOFFICE editor by default

Nextcloud Server version

30

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

Configuration report

No response

List of activated Apps

No response

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

@juliusknorr, could you please take a look?

blizzz commented 3 days ago

@artonge @susnux isn't it similar to what we tackled with https://github.com/nextcloud/viewer/pull/2368 and https://github.com/nextcloud/server/pull/47016?

juliusknorr commented 2 days ago

I've been reproducing this and noticed that it seems to be caused by the use of window.history.pushState which likely causes side effects with the vue router that is used in files now. It seems that after the use of pushState when opening or closing a file the next call to open the new file with OCP.Files.Router.goToRoute is no longer doing anything.

@susnux @skjnldsv Is that a known thing for the vue/files router?

A quick attempt to fix this is the following patch for the onlyoffice app would be this:

diff --git a/src/main.js b/src/main.js
index e04170c..f32f13e 100644
--- a/src/main.js
+++ b/src/main.js
@@ -179,7 +179,11 @@ import NewPdfSvg from '!!raw-loader!../img/new-pdf.svg';
                        $(OCA.Onlyoffice.frameSelector).css('top', scrollTop)

                        OCA.Onlyoffice.folderUrl = location.href
-                       window.history.pushState(null, null, url)
+                       window.OCP.Files.Router.goToRoute(
+                               null, // use default route
+                               OCP.Files.Router.params,
+                               { ...OCP.Files.Router.query, openfile: 'true' },
+                       )
                }
        }

@@ -193,7 +197,11 @@ import NewPdfSvg from '!!raw-loader!../img/new-pdf.svg';
                let url = OCA.Onlyoffice.folderUrl
                url = url.replace(/&?openfile=true/, '')
                if (url) {
-                       window.history.pushState(null, null, url)
+                       window.OCP.Files.Router.goToRoute(
+                               null, // use default route
+                               OCP.Files.Router.params,
+                               { ...OCP.Files.Router.query, openfile: 'false' },
+                       )
                        OCA.Onlyoffice.folderUrl = null
                }
        }
susnux commented 2 days ago

Is that a known thing for the vue/files router

I remember something like this in the legacy Vue2 router but can not find any reference anymore.. This is known, so just do not use the history manually:

https://github.com/vuejs/router/issues/956