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

De-duplicate event handling to prevent errors on Draw-io #8576

Merged
merged 1 commit into from
Mar 13, 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
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: De-duplicate event handling to prevent errors on Draw-io

If users navigated out of Draw-io and returned afterwards, old event handlers were kept, which failed trying to look for iframes that no longer existed.
This fix removes the handlers when exiting, preventing these user visible errors.

https://github.com/owncloud/web/pull/8576
52 changes: 28 additions & 24 deletions packages/web-app-draw-io/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,10 @@ export default defineComponent({
created() {
this.filePath = this.currentFileContext.path
this.fileExtension = this.filePath.split('.').pop()
window.addEventListener('message', (event) => {
if (event.data.length > 0) {
if (event.origin !== this.config.url) {
return
}
const payload = JSON.parse(event.data)
switch (payload.event) {
case 'init':
this.fileExtension === 'vsdx' ? this.importVisio() : this.load()
break
case 'autosave':
if (this.isAutoSaveEnabled) {
this.save(payload, true)
}
break
case 'save':
this.save(payload)
break
case 'exit':
this.exit()
break
}
}
})
window.addEventListener('message', this.handleMessage)
},
beforeUnmount() {
window.removeEventListener('message', this.handleMessage)
},
methods: {
...mapActions(['showMessage']),
Expand Down Expand Up @@ -142,6 +122,30 @@ export default defineComponent({
this.errorPopup(error)
}
},
async handleMessage(event) {
if (event.data.length > 0) {
if (event.origin !== this.config.url) {
return
}
const payload = JSON.parse(event.data)
switch (payload.event) {
case 'init':
this.fileExtension === 'vsdx' ? this.importVisio() : this.load()
break
case 'autosave':
if (this.isAutoSaveEnabled) {
this.save(payload, true)
}
break
case 'save':
this.save(payload)
break
case 'exit':
this.exit()
break
}
}
},
async loadFileContent() {
try {
const response = await this.getFileContents(this.currentFileContext)
Expand Down