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

fix(sidebar): Only load chunk once #1363

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, webpack doesn't cache the chunk here? That's weird.

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