From f556630749fc465dde255dc7a26a246d02a3397f Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 27 Jul 2025 15:14:42 +0200 Subject: [PATCH 1/2] fix(richworkspace): toggle localHasRichWorkspace right away Awaiting the request for the file lead to race conditions: * Enter directory with rich workspace, loading is triggered. * Navigate to directory without rich workspace. * Loading finishes - rich workspace was shown. Also clean up some minor things: * `this.creating` was not used at all. * The Editor does not emit `error`. Signed-off-by: Max --- src/views/RichWorkspace.vue | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/views/RichWorkspace.vue b/src/views/RichWorkspace.vue index e46a20419d2..8053187caac 100644 --- a/src/views/RichWorkspace.vue +++ b/src/views/RichWorkspace.vue @@ -5,7 +5,7 @@ @@ -89,6 +88,7 @@ export default { loaded: false, ready: false, autofocus: false, + shouldAutofocus: false, hideMenu: true, darkTheme: window?.OCA?.Accessibility?.theme === 'dark', enabled: window?.OCA?.Text?.RichWorkspaceEnabled, @@ -98,10 +98,16 @@ export default { shareToken() { return getSharingToken() }, + shouldRender() { + return this.enabled && this.localHasRichWorkspace + }, }, watch: { path() { - this.getFileInfo() + this.reset() + }, + ready() { + this.shouldAutofocus = false }, focus(newValue) { if (!newValue) { @@ -110,18 +116,17 @@ export default { .scrollTo(0, 0) } }, - hasRichWorkspace(value) { - this.localHasRichWorkspace = value + shouldRender(value) { if (value) { this.getFileInfo() } }, + hasRichWorkspace(value) { + this.localHasRichWorkspace = value + }, }, mounted() { this.localHasRichWorkspace = this.hasRichWorkspace - if (this.enabled && this.hasRichWorkspace) { - this.getFileInfo() - } subscribe('Text::showRichWorkspace', this.showRichWorkspace) subscribe('Text::hideRichWorkspace', this.hideRichWorkspace) subscribe('files:node:created', this.onFileCreated) @@ -146,22 +151,19 @@ export default { this.unlistenKeydownEvents() }, reset() { - this.localHasRichWorkspace = false this.file = null this.focus = false + this.shouldAutofocus = false this.$nextTick(() => { - this.creating = false - this.getFileInfo() + if (this.shouldRender) { + this.getFileInfo() + } }) }, - getFileInfo(autofocus) { - if (!this.enabled) { - return - } + getFileInfo() { this.file = null this.ready = false this.loaded = true - this.autofocus = false const params = { path: this.path } if (IS_PUBLIC) { params.shareToken = this.shareToken @@ -174,8 +176,7 @@ export default { this.file = data.file this.editing = true this.loaded = true - this.autofocus = autofocus || false - this.localHasRichWorkspace = true + this.autofocus = this.shouldAutofocus return true }) .catch((error) => { @@ -190,13 +191,11 @@ export default { this.file = null this.loaded = true this.ready = true - this.creating = false return false }) }, showRichWorkspace(event) { this.enabled = true - this.getFileInfo(event?.autofocus || false) }, hideRichWorkspace() { this.enabled = false @@ -214,8 +213,8 @@ export default { }, onFileCreated(node) { if (SUPPORTED_STATIC_FILENAMES.includes(node.basename)) { + this.shouldAutofocus = this.enabled this.localHasRichWorkspace = true - this.getFileInfo(true) } }, onFileDeleted(node) { From 1a8f2879342cd69dc1da5506bf2256b539278326 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 27 Jul 2025 15:37:54 +0200 Subject: [PATCH 2/2] fix(workspace): do not render if not enabled The header is just hidden if enabled is false. But for the workspace this leads to continuous requests updating the content. Signed-off-by: Max --- src/helpers/files.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/helpers/files.js b/src/helpers/files.js index 06d09670dea..8ece2900f8d 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -192,13 +192,15 @@ let FilesHeaderRichWorkspaceView let FilesHeaderRichWorkspaceInstance let latestFolder +function enabled(_, view) { + return ['files', 'favorites', 'public-share'].includes(view.id) +} + export const FilesWorkspaceHeader = new Header({ id: 'workspace', order: 10, + enabled, - enabled(_, view) { - return ['files', 'favorites', 'public-share'].includes(view.id) - }, render: async (el, folder) => { latestFolder = folder // Import the RichWorkspace component only when needed @@ -231,14 +233,15 @@ export const FilesWorkspaceHeader = new Header({ window.FilesHeaderRichWorkspaceInstance = FilesHeaderRichWorkspaceInstance }, - updated(folder) { + updated(folder, view) { latestFolder = folder if (!FilesHeaderRichWorkspaceInstance) { console.error('No vue instance found for FilesWorkspaceHeader') return } - const hasRichWorkspace = !!folder.attributes['rich-workspace-file'] + const hasRichWorkspace = + !!folder.attributes['rich-workspace-file'] && enabled(folder, view) FilesHeaderRichWorkspaceInstance.hasRichWorkspace = hasRichWorkspace FilesHeaderRichWorkspaceInstance.content = folder.attributes['rich-workspace'] || ''