Skip to content

Commit 02aa515

Browse files
committed
chore(performance): use async components properly
No need to await the import the moment we import the component. Vue handles this fine when the component is actually needed. Signed-off-by: Max <max@nextcloud.com>
1 parent dd87d60 commit 02aa515

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/editor.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { emit, subscribe } from '@nextcloud/event-bus'
7-
import Vue from 'vue'
7+
import Vue, { defineAsyncComponent } from 'vue'
88
import {
99
ATTACHMENT_RESOLVER,
1010
EDITOR_UPLOAD,
@@ -265,10 +265,10 @@ window.OCA.Text.createEditor = async function ({
265265
onSearch = undefined,
266266
onAttachmentsUpdated = ({ attachmentSrcs }) => {},
267267
}) {
268-
const { default: MarkdownContentEditor } = await import(
269-
'./components/Editor/MarkdownContentEditor.vue'
268+
const MarkdownContentEditor = defineAsyncComponent(
269+
() => import('./components/Editor/MarkdownContentEditor.vue'),
270270
)
271-
const { default: Editor } = await import('./components/Editor.vue')
271+
const Editor = defineAsyncComponent(() => import('./components/Editor.vue'))
272272

273273
const data = Vue.observable({
274274
readonlyBarProps: readonlyBar.props,
@@ -365,8 +365,8 @@ window.OCA.Text.createTable = async function ({
365365
onLoaded = () => {},
366366
onUpdate = ({ markdown }) => {},
367367
}) {
368-
const { default: PlainTableContentEditor } = await import(
369-
'./components/Editor/PlainTableContentEditor.vue'
368+
const PlainTableContentEditor = defineAsyncComponent(
369+
() => import('./components/Editor/PlainTableContentEditor.vue'),
370370
)
371371

372372
const data = Vue.observable({

src/files.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ const openReadOnlyEnabled = loadState('text', 'open_read_only_enabled')
1414

1515
document.addEventListener('DOMContentLoaded', async () => {
1616
if (workspaceAvailable && window.OCA.Files?.Settings) {
17-
const { default: Vue } = await import('vue')
18-
const { default: FilesSettings } = await import('./views/FilesSettings.vue')
19-
17+
const { default: Vue, defineAsyncComponent } = await import('vue')
18+
const FilesSettings = defineAsyncComponent(
19+
() => import('./views/FilesSettings.vue'),
20+
)
2021
const vm = new Vue({
2122
render: (h) => h(FilesSettings, {}),
2223
})

0 commit comments

Comments
 (0)