Skip to content

Commit

Permalink
Merge pull request #1363 from nextcloud/fix/only-load-once
Browse files Browse the repository at this point in the history
fix(sidebar): Only load chunk once
  • Loading branch information
susnux authored Oct 12, 2023
2 parents 57064cd + 312ca53 commit 94f6c6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions js/activity-sidebar.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ const activityTab = new OCA.Files.Sidebar.Tab({
iconSvg: LightningBolt,

async mount(el, fileInfo, context) {
const { default: ActivityTab } = await import(/* webpackPreload: true */ './views/ActivityTab.vue')
ActivityTabView = ActivityTabView ?? Vue.extend(ActivityTab)
// only load if needed
if (ActivityTabView === null) {
const { default: ActivityTab } = await import('./views/ActivityTab.vue')
ActivityTabView = ActivityTabView ?? Vue.extend(ActivityTab)
}
// destroy previous instance if available
if (ActivityTabInstance) {
ActivityTabInstance.$destroy()
}
ActivityTabInstance = new ActivityTabView({
// Better integration with vue parent component
parent: context,
})
// Only mount after we have all the info we need
await ActivityTabInstance.update(fileInfo)
// No need to await this, we will show a loading indicator instead
ActivityTabInstance.update(fileInfo)
ActivityTabInstance.$mount(el)
},
update(fileInfo) {
Expand All @@ -63,7 +67,7 @@ const activityTab = new OCA.Files.Sidebar.Tab({
},
})

window.addEventListener('DOMContentLoaded', async function () {
window.addEventListener('DOMContentLoaded', async function() {
if (OCA.Files && OCA.Files.Sidebar) {
OCA.Files.Sidebar.registerTab(activityTab)
const { default: ActivityTab } = await import(/* webpackPreload: true */ './views/ActivityTab.vue')
Expand Down

0 comments on commit 94f6c6e

Please sign in to comment.