Skip to content

Commit

Permalink
De-duplicate event handling to prevent errors on Draw-io
Browse files Browse the repository at this point in the history
  • Loading branch information
diocas committed Mar 13, 2023
1 parent 1bb1ea4 commit 8d84102
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
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

0 comments on commit 8d84102

Please sign in to comment.