richdocuments icon indicating copy to clipboard operation
richdocuments copied to clipboard

Files sometimes do not get opened immediately on internal links

Open juliusknorr opened this issue 1 year ago • 17 comments

Steps to reproduce

  1. Have an internal link like /f/1234
  2. Open it in a browser (e.g. from clicking in an email)

Expected behaviour

The file should open

Actual behaviour

Sometimes the file doesn't open automatically and there is an error thrown. It seems happening more often with cleared browser cache.

Now the odd thing here is that the error is thrown before the viewer app is initialized, so there seems to be some kind of timing issue when trying to get the file actions for the requested file.

https://github.com/nextcloud/server/pull/45586 would help with the error but I cannot see how it would solve the file then just not opening up.

I have not managed to reproduce this locally on any of the versions, but tech-preview is affected (currently on 29.0.0) and another instance on 28.0.6 (both should be upgraded 🙈 )

@susnux Do you have any idea on why the order in which the handleOpenFile and the viewer registrations would be executed might differ?

Screenshot 2024-07-09 at 10 05 21 Screenshot 2024-07-09 at 10 06 15

juliusknorr avatar Jul 09 '24 08:07 juliusknorr

Upgraded the 29 instance to 29.0.3, still reproducible sometimes, but now without an error

Edit: Still one for the sidebar:

Screenshot 2024-07-09 at 10 47 04

juliusknorr avatar Jul 09 '24 08:07 juliusknorr

cc'ing as requested: @mmeeks @karlitschek

pedropintosilva avatar Jul 09 '24 10:07 pedropintosilva

We are running 28.0.8 and can still confirm the issue is happening sometimes.

bentuna avatar Aug 01 '24 11:08 bentuna

I had a chat with @susnux about this and this seems to be a design flaw of the viewer api registering the file type handlers too late. He will think about a possible workaround.

juliusknorr avatar Aug 01 '24 11:08 juliusknorr

@susnux I looked a bit further into it while fixing a regression with 30 https://github.com/nextcloud/server/pull/47014

I still have not managed to trigger this race condition locally. I tried to think about a way to fake this timing issue but cannot figure out how I could manually delay the viewer registration like it is happening on those affected systems. But thought about a workaround like this, kind of deferring the handleOpenFile until the DOMContentLoaded event from viewer has registered the file actions.

diff --git a/apps/files/src/components/FilesListVirtual.vue b/apps/files/src/components/FilesListVirtual.vue
index 233353d0985..62cc53fd093 100644
--- a/apps/files/src/components/FilesListVirtual.vue
+++ b/apps/files/src/components/FilesListVirtual.vue
@@ -209,7 +209,7 @@ export default defineComponent({
                const { id } = loadState<{ id?: number }>('files', 'fileInfo', {})
                this.scrollToFile(id ?? this.fileId)
                this.openSidebarForFile(id ?? this.fileId)
-               this.handleOpenFile(id ?? null)
+               this.handleOpenFileOnLoad(id ?? null)
        },

        beforeDestroy() {
@@ -242,6 +242,18 @@ export default defineComponent({
                        }
                },

+               handleOpenFileOnLoad(fileId: number|null) {
+                       // This is a workaround as the viewer api registers file actions too late
+                       // Some might not be ready yet
+                       if (document.readyState === 'complete') {
+                               this.$nextTick(() => this.handleOpenFile(fileId))
+                       } else {
+                               window.addEventListener('load', () => {
+                                       this.$nextTick(() => this.handleOpenFile(fileId))
+                               })
+                       }
+               },
+
                /**
                 * Handle opening a file (e.g. by ?openfile=true)
                 * @param fileId File to open
                 * 

juliusknorr avatar Aug 03 '24 10:08 juliusknorr

kind of deferring the handleOpenFile until the DOMContentLoaded event from viewer has registered the file actions.

This I would say makes sense, though it would cause visual delays on slow connection. But should be a good fix.

susnux avatar Aug 03 '24 12:08 susnux

Thanks Julius - this plagues me many times per day =)

mmeeks avatar Aug 05 '24 16:08 mmeeks

Hello and thanks for the https://github.com/nextcloud/viewer/pull/2486 @susnux! I see that @artonge has tried to backported with https://github.com/nextcloud/viewer/pull/2490 to [stable29] but it seems there is the need to rebase it and there are some conflicts. If there is anything I can test please let me know.

pedropintosilva avatar Oct 15 '24 08:10 pedropintosilva

Thanks @artonge , I see it's not in! Good so it should be include in 28 and 29 release. The fix is include 3.0.1 (17 oct).

@annanazaryan : (to be confirmed) it seems in our staging it's still reproducible (30.0.2 RC1) cc: @jazevedo-coll

pedropintosilva avatar Nov 05 '24 13:11 pedropintosilva

(to be confirmed) it seems in our staging it's still reproducible (30.0.2 RC1)

@pedropintosilva what I have seen with our staging instance is: when opening an internal link on a browser with a clean cache and history and site settings, sometimes the file will not open and will just download instead.

Image

jazevedo-coll avatar Nov 06 '24 21:11 jazevedo-coll

Is it possible that there is some async / defer / fetchpriority foo going on that sometimes perturbs the order of execution and initialization of the different JS modules themselves ?

mmeeks avatar Nov 07 '24 08:11 mmeeks

@eszkadev Brought up this was still happening on tech-preview instance

juliusknorr avatar Jan 28 '25 12:01 juliusknorr

I was able to produce this exact behavior for a text file by delaying requests to /apps/text/js/text-files.* .

So far we were thinking richdocuments may try to register the file handler before the viewer is even ready. Now I believe that it's the opposite. The richdocuments script is taking too long to load so the viewer tries to open it before the script has been parsed. As it has not been parsed yet there's no handler and the viewer falls back to downloading the file.

One workaround might be to wait for the entire page to load. The other option would be to register the handler from within the html source of the page itself.

max-nextcloud avatar Apr 03 '25 13:04 max-nextcloud

We could move the registration of viewer handlers into init scripts just like viewer moved its own initialization into an init script here: https://github.com/nextcloud/viewer/pull/2486

max-nextcloud avatar Apr 08 '25 09:04 max-nextcloud

Next steps:

  • [x] Clarify after the release of https://github.com/nextcloud/richdocuments/pull/4680 if this is still an issue
  • [ ] If not we may have two options
    • [ ] Client side, register as globals like we do with the file actions api in @nextcloud/files
    • [ ] Server side, load handler registration scripts as init but after viewer

juliusknorr avatar May 08 '25 09:05 juliusknorr

@mmeeks I'd be curious if you have richdocuments v8.5.7 installed on the Nextcloud instance that you encountered this regularly and if since that version there is some difference in how often this occurs?

juliusknorr avatar Jun 04 '25 14:06 juliusknorr

@juliusknorr we are running v8.5.4 on the instance in question. We plan to update to v8.5.7, once we have we will keep an eye on it to see if it is better and report back

mitchtester avatar Jun 09 '25 10:06 mitchtester

I had an exciting change this morning - no idea what got upgraded; perhaps @mitchtester would know. I followed a direct link to the document, it failed to load -and- I got a beautiful popup at the top saying something like: "There is no plugin registered for this document type" or something (?) =) will try to get a picture of it next time in case it helps.

mmeeks avatar Aug 27 '25 09:08 mmeeks

I can confirm that I also encountered this popup. It happened when I tried to open a publicly shared link.

annanazarayan avatar Aug 27 '25 10:08 annanazarayan

Is there an open version of this bug? Documents basically never load first time for me, always fine after a refresh. This doesn't seem fixed to me at all, but perhaps my experience/path is different to this one somehow?

Cwiiis avatar Sep 16 '25 08:09 Cwiiis

It happened to me today, got no popup, downloaded at least 7 copies of the same file and no amount of reloading seemed to fix it. After approximately ten minutes that the tab was left open the editor appeared. Is there a way as a user to know the version of richdocuments in use?

emanueleaina avatar Oct 07 '25 18:10 emanueleaina

Which version are you running? This should be fixed in latest maintenance releases of all supported Nextcloud versions (31.0.9 and 32.0.0) when running the latest richdocuments version.

susnux avatar Oct 07 '25 18:10 susnux

Nextcloud Enterprise 31.0.9 (which aiui is the latest Enterprise version) and also latest Nextcloud Office (richdocuments) 8.7.5.

emanueleaina avatar Oct 12 '25 09:10 emanueleaina

I'm trying to get reproducible steps, still no luck. Nevertheless, @jazevedo-coll has also see this with nextcloud 31.0.9.2 - richdocuments 8.7.5, firefox after having cleaned the browser cache and opening a password protected shared link.

@thorstenb has also experienced this but when clicking in urls that user has copied from his web browser address bar: https://domain.com/index.php/apps/files/files/12345678?dir=/folder-name&editing=false&openfile=true

pedropintosilva avatar Oct 15 '25 12:10 pedropintosilva

So what seems to work around the issue for me is to navigate to the parent folder and back to the one with the file to open. At that point I can edit the file.

emanueleaina avatar Oct 15 '25 14:10 emanueleaina

I got logs from another @printfdebugging here is his logs, in this case, after opening a file via public shared link (with password) the files view opens empty and remains empty

```

[ERROR] files: SW registration failed:
Object { app: "files", level: 1, error: DOMException } core-common.js:1:2268719 Content-Security-Policy: The page’s settings blocked a worker script (worker-src) at https://share.collabora.com/index.php/apps/files/preview-service-worker.js from being executed because it violates the following directive: “script-src 'nonce-k70oH/krTqhP7FEpXeSMnpz2f74GpQEvHM6fq1vAmPE='” files-init.js:1:62321 [ERROR] files_sharing: Unexpected Error "Invalid response: 401 Unauthorized" Object { app: "files_sharing", level: 1, error: Error } core-common.js:1:2268719 [ERROR] files: Error while fetching content Object { app: "files", level: 1, error: Error } core-common.js:1:2268719 TypeError: can't access property "fileid", this.currentFolder is undefined scrollToFile FilesListVirtual.vue:195 handler FilesListVirtual.vue:133 fn core-common.js:1 $watch core-common.js:1 Ra core-common.js:1 _init core-common.js:1 _init core-common.js:1 _init core-common.js:1 o core-common.js:1 componentInstance core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 C core-common.js:1 C core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 run core-common.js:1 sa core-common.js:1 Cn core-common.js:1 bn core-common.js:1 core-common.js:1:4053543 TypeError: can't access property "attributes", e is undefined enabled files_sharing-init.js:1 enabled FilesListHeader.vue:34 get core-common.js:1 evaluate core-common.js:1 Oa core-common.js:1 getter core-common.js:1 get core-common.js:1 e core-common.js:1 $watch core-common.js:1 Ra core-common.js:1 _init core-common.js:1 _init core-common.js:1 _init core-common.js:1 o core-common.js:1 componentInstance core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 m core-common.js:1 h core-common.js:1 m core-common.js:1 h core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 e core-common.js:1 mount core-common.js:1 $mount core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 e core-common.js:1 mount core-common.js:1 $mount core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 C core-common.js:1 C core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 run core-common.js:1 sa core-common.js:1 Cn core-common.js:1 bn core-common.js:1 core-common.js:1:4053543 TypeError: can't access property "attributes", e is undefined enabled files_sharing-init.js:1 enabled FilesListHeader.vue:34 get core-common.js:1 evaluate core-common.js:1 Oa core-common.js:1 us FilesListHeader.vue:1 _render core-common.js:1 a core-common.js:1 get core-common.js:1 e core-common.js:1 mount core-common.js:1 $mount core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 m core-common.js:1 h core-common.js:1 m core-common.js:1 h core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 e core-common.js:1 mount core-common.js:1 $mount core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 e core-common.js:1 mount core-common.js:1 $mount core-common.js:1 init core-common.js:1 h core-common.js:1 h core-common.js:1 C core-common.js:1 C core-common.js:1 Si core-common.js:1 _update core-common.js:1 a core-common.js:1 get core-common.js:1 run core-common.js:1 sa core-common.js:1 Cn core-common.js:1 bn core-common.js:1 core-common.js:1:4053543 TypeError: can't access property "fileid", this.currentFolder is undefined mounted FilesList.vue:337 core-common.js:1:4053543 [ERROR] files: Error rendering workspace FilesListHeader Object { app: "files", level: 1, header: {…}, error: TypeError } core-common.js:1:2268719


</details>

pedropintosilva avatar Oct 16 '25 10:10 pedropintosilva

I started using the new thing from the office wifi and the experience was dramatically worse having upgraded; three+ downloads from a re-loaded URL eg. - I did a quick dump of some dates and unexpected Downloads to show this off - from the timestamps it is possible to see that what was once/twice per day was (at least yesterday) rather more though I was at a different location; will monitor today

Oct 16 13:20 XxxxXxxxxx xxxxxxxxxxxxx xxxxxxx.xxxx
Oct 15 13:57 xxxxxx-xxxx-xxxxx (2).xxx
Oct 15 13:56 xxxxxx-xxxx-xxxxx (1).xxx
Oct 15 13:56 xxxxxx-xxxx-xxxxx.xxx
Oct 15 10:57 Xxxxxxxxx Xxxxxx Xxxxxxx.xxxx
Oct 15 10:54 Xxxxxxx Xxxx XXXX (1).xxx
Oct 15 10:54 Xxxxxxx Xxxx XXXX.xxx
Oct 15 10:53 Xxxxx & Xxxxxxxxx Xxxx Xx Xxx 2025.xxxx
Oct 10 10:03 xxxx-xxxxx (12).xxx
Oct  9 15:58 Xxxxxxx (8).xxx
Oct  9 15:58 Xxxxxxx (7).xxx
Oct  9 12:51 Xxxxxxx-Xxxxxxxxx-Xxxxxxx (7).xxx
Oct  8 15:02 Xxxxx-Xxxx-Xxxxxx (2).xxxx
Oct  8 11:44 xxxxxxxxxx xxxxxxx xxxxxxxx.xxx
Oct  8 11:14 xxxx-2025-10-08.xxx
Oct  8 11:08 xxxx-2025-09-02.xxxx
Oct  3 10:00 XXXXxxxxxxx Xxxxxxx Xxxxxxxxx Xxxxxxxxx_Xxxxxxxxx (XXX Xxxxx 10-1-25).xxxx
Oct  2 15:09 Xxxx Xxxxxxxxx Xxxxxxxxxxx.xxx
Oct  2 13:48 Xxx Xxxx Xxxxxxxx.xxx
Oct  2 09:47 xxxx-xxxxxxxx-xxxx-2025-10-02.xxx
Sep 30 16:53 xxxxxxx-xxxxx-xxx.xxxx
Sep 28 11:38 xxx61112-1.xxxx
Sep 26 19:53 xxxx-xxxx.xxxx
Sep 26 14:45 Xxxxxxx xx Xxxxxxxxx Xxx.xxxx
Sep 25 09:48 xxxx-xxxxxxxx-xxxx-2025-09-25.xxx
Sep 24 14:30 Xxxxx xxxxxxx_ Xxxxxxxx Xxxxx Xxxxxx-XXX-x1.xxxx
Sep 24 13:07 xxxxxxx-2025-Xxxx (1).xxx
Sep 23 15:58 xxxxxxx-2025-Xxxxxx.xxxx
Sep 23 14:58 xxxxxxx-2025-Xxxx.xxx
Sep 22 13:02 Xxxxxxx-Xxxxxxxxx-Xxxxxxx (6).xxx
Sep 18 17:43 xxxxxxx-xxxxxxx-xxxxxx-xx-xxxxxxxxxx-2025-02-21_09.19.18.xxx
Sep 18 14:01 Xxxx-2025-09-18.xxxx
Sep 17 17:25 XX Xxxxxxxx.xxx
Sep 17 12:12 XxxxxxXxxx (1).xxx

mmeeks avatar Oct 17 '25 08:10 mmeeks

Today I was able to reproduce it by using the web browser's back button :

  1. Open an office document
  2. Press back from web browser to go back to a folder view
  3. Click on another office document
  4. It downloads the file instead of opening it

pedropintosilva avatar Oct 17 '25 09:10 pedropintosilva

For following a link to a document. Javascript console output, might be indicative:

11:02:06.707 index.mjs:54 [ERROR] files: Error while opening sidebar Object log @ index.mjs:54

Bad:

11:02:06.047 index.mjs:48 [INFO] activity: Activity API registered Object
11:02:06.077 index.mjs:51 [WARN] viewer: Some mimes were ignored because they are not enabled in the server previews config Object
log @ index.mjs:51
11:02:06.204 Settings.js:12 OCA.Files.Settings initialized
11:02:06.304 Sidebar.js:19 OCA.Files.Sidebar initialized
11:02:06.360 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:06.477 ShareSearch.js:16 OCA.Sharing.ShareSearch initialized
11:02:06.477 ExternalLinkActions.js:16 OCA.Sharing.ExternalLinkActions initialized
11:02:06.477 ExternalShareActions.js:16 OCA.Sharing.ExternalShareActions initialized
11:02:06.707 index.mjs:54 [ERROR] files: Error while opening sidebar Object
log @ index.mjs:54
11:02:06.877 comments-app.js:15 OCA.Comments.View initialized
11:02:06.880 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:07.227 NotificationsApp.vue:417 Notifications permissions granted
11:02:07.229 NotificationsApp.vue:380 Polling interval updated to 30000
11:02:07.229 NotificationsApp.vue:251 Started background fetcher as session_keepalive is enabled
11:02:07.244 index.mjs:48 [INFO] files: Initializing unified search plugin: folder search from files app Object
11:02:07.245 index.mjs:48 [INFO] viewer: 6 viewer handlers registered Object
11:02:07.246 index.mjs:48 [INFO] core: session heartbeat polling started Object
11:02:07.303 index.mjs:48 [INFO] comments: Comments plugin registered for Activity sidebar action Object
11:02:07.305 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:07.448 NotificationsApp.vue:336 Got notification data, restoring default polling interval.
11:02:07.568 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:07.939 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:27.705 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:29.867 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:37.235 NotificationsApp.vue:336 Got notification data, restoring default polling interval.

Good:

11:02:21.693 index.mjs:48 [INFO] activity: Activity API registered Object
11:02:21.714 index.mjs:51 [WARN] viewer: Some mimes were ignored because they are not enabled in the server previews config Object
log @ index.mjs:51
11:02:21.791 Settings.js:12 OCA.Files.Settings initialized
11:02:21.848 Sidebar.js:19 OCA.Files.Sidebar initialized
11:02:21.873 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:21.952 ShareSearch.js:16 OCA.Sharing.ShareSearch initialized
11:02:21.953 ExternalLinkActions.js:16 OCA.Sharing.ExternalLinkActions initialized
11:02:21.953 ExternalShareActions.js:16 OCA.Sharing.ExternalShareActions initialized
11:02:22.026 comments-app.js:15 OCA.Comments.View initialized
11:02:22.119 index.mjs:48 [INFO] files: Initializing unified search plugin: folder search from files app Object
11:02:22.121 index.mjs:48 [INFO] viewer: 6 viewer handlers registered Object
11:02:22.121 index.mjs:48 [INFO] core: session heartbeat polling started Object
11:02:22.150 index.mjs:48 [INFO] comments: Comments plugin registered for Activity sidebar action Object
11:02:22.153 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:22.301 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:22.380 NotificationsApp.vue:417 Notifications permissions granted
11:02:22.382 NotificationsApp.vue:380 Polling interval updated to 30000
11:02:22.382 NotificationsApp.vue:251 Started background fetcher as session_keepalive is enabled
11:02:22.437 index.mjs:48 [INFO] viewer: Opening viewer for file  Object
11:02:22.439 index.mjs:51 [WARN] viewer: No files provided, skipping update Object
log @ index.mjs:51
11:02:22.500 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:22.651 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:22.661 NotificationsApp.vue:336 Got notification data, restoring default polling interval.
11:02:22.775 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:22.832 Viewer.vue:669 File info for /Productivity/Marketing/....
11:02:23.024 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:23.164 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:23.185 url.js:28 [getWopiUrl] https://share.collabora.com/index.php/apps/richdocuments/wopi/files/...
11:02:23.295 Office.vue:383 [viewer] Received post message App_LoadingStatus Object false
11:02:23.457 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:23.699 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:24.064 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:24.223 Office.vue:383 [viewer] Received post message App_LoadingStatus Object false
11:02:24.229 Office.vue:383 [viewer] Received post message Action_Load_Resp Object false
11:02:24.230 postMessage.tsx:25 PostMessageService.sendPostMessage FRAME_DOCUMENT {"MessageId":"Host_PostmessageReady","SendTime":1760695344230,"Values":{}}
11:02:24.230 postMessage.tsx:25 PostMessageService.sendPostMessage FRAME_DOCUMENT {"MessageId":"Insert_Button","SendTime":1760695344230,"Values":{"id":"Open_Local_Editor","imgurl":"https://share.collabora.com/apps/richdocuments/img/launch.svg","mobile":false,"label":"Open in local editor","hint":"Open in local editor","insertBefore":"print"}}
11:02:24.231 global.js:1 Received Host_PostmessageReady.
11:02:24.302 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:24.596 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:24.907 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)
11:02:25.221 background?v=26:1  Failed to load resource: the server responded with a status of 404 (Not Found)

mmeeks avatar Oct 17 '25 10:10 mmeeks

Tentatively re-opening, I hope that's ok.

mmeeks avatar Oct 17 '25 12:10 mmeeks