Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/duplicated load of yjs #4542

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/components/Editor.singleton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Get instance of Editor component
luka-nextcloud marked this conversation as resolved.
Show resolved Hide resolved
* Using singleton approach here to avoid duplicate yjs import error
* @return {Promise<*>}
*/
export default async function getEditorInstance() {
if (!window._nc_text_editor_instance) {
if (window._nc_text_editor_importing) {
return await new Promise((resolve) => {
const intervalId = setInterval(() => {
if (!window._nc_text_editor_instance) {
return
}
resolve(window._nc_text_editor_instance)
clearInterval(intervalId)
}, 200)
})
} else {
window._nc_text_editor_importing = true
}
const Editor = await import(/* webpackChunkName: "editor" */'./Editor.vue')
window._nc_text_editor_instance = Editor.default
}
return window._nc_text_editor_instance
}
3 changes: 2 additions & 1 deletion src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ import PlainTextReader from './PlainTextReader.vue'
import RichTextReader from './RichTextReader.vue'

import { getSharingToken } from '../helpers/token.js'
import getEditorInstance from './Editor.singleton.js'

export default {
name: 'ViewerComponent',
components: {
RichTextReader,
PlainTextReader,
Editor: () => import(/* webpackChunkName: "editor" */'./Editor.vue'),
Editor: getEditorInstance,
},
props: {
filename: {
Expand Down
3 changes: 2 additions & 1 deletion src/views/RichWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import SkeletonLoading from '../components/SkeletonLoading.vue'
import getEditorInstance from '../components/Editor.singleton.js'

const IS_PUBLIC = !!(document.getElementById('isPublic'))
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
Expand All @@ -54,7 +55,7 @@ export default {
name: 'RichWorkspace',
components: {
SkeletonLoading,
Editor: () => import(/* webpackChunkName: "editor" */'./../components/Editor.vue'),
Editor: getEditorInstance,
},
props: {
path: {
Expand Down