Skip to content

Commit

Permalink
fix: yjs duplicated import issue
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Jul 24, 2023
1 parent 26ed4bc commit e37da6f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/components/Editor.singleton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Get instance of Editor component
* @return {Promise<*>}
*/
export default async function getEditorInstance() {
if (!window.EditorInstance) {
if (window.EditorInstanceImporting) {
return await new Promise((resolve) => {
const intervalId = setInterval(() => {
if (!window.EditorInstance) {
return
}
resolve(window.EditorInstance)
clearInterval(intervalId)
}, 200)
})
} else {
window.EditorInstanceImporting = true
}
const Editor = await import(/* webpackChunkName: "editor" */'./Editor.vue')
window.EditorInstance = Editor.default
}
return window.EditorInstance
}
3 changes: 2 additions & 1 deletion src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@

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

export default {
name: 'ViewerComponent',
components: {
Editor: () => import(/* webpackChunkName: "editor" */'./Editor.vue'),
Editor: async () => { return await 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 @@ -44,14 +44,15 @@
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import getEditorInstance from '../components/Editor.singleton.js'

const IS_PUBLIC = !!(document.getElementById('isPublic'))
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)

export default {
name: 'RichWorkspace',
components: {
Editor: () => import(/* webpackChunkName: "editor" */'./../components/Editor.vue'),
Editor: async () => { return await getEditorInstance() },
},
props: {
path: {
Expand Down

0 comments on commit e37da6f

Please sign in to comment.