Fix intermittent crash due to invalid iframe reference when hot reloading

This commit is contained in:
Andrew Kingston 2021-09-16 16:27:19 +01:00
parent d368e54d17
commit f88ef064b1
1 changed files with 13 additions and 7 deletions

View File

@ -104,8 +104,10 @@
// remove all iframe event listeners on component destroy // remove all iframe event listeners on component destroy
onDestroy(() => { onDestroy(() => {
if (iframe.contentWindow) {
iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent) iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent)
iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent) iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent)
}
}) })
const handleBudibaseEvent = event => { const handleBudibaseEvent = event => {
@ -123,17 +125,21 @@
} else { } else {
console.warning(`Client sent unknown event type: ${type}`) console.warning(`Client sent unknown event type: ${type}`)
} }
}; }
const handleKeydownEvent = event => { const handleKeydownEvent = event => {
if ((event.key === "Delete" || event.key === "Backspace") && if (
(event.key === "Delete" || event.key === "Backspace") &&
selectedComponentId && selectedComponentId &&
['input', 'textarea'].indexOf(iframe.contentWindow.document.activeElement?.tagName.toLowerCase()) === -1) { ["input", "textarea"].indexOf(
confirmDeleteComponent(selectedComponentId); iframe.contentWindow.document.activeElement?.tagName.toLowerCase()
) === -1
) {
confirmDeleteComponent(selectedComponentId)
} }
} }
const confirmDeleteComponent = (componentId) => { const confirmDeleteComponent = componentId => {
idToDelete = componentId idToDelete = componentId
confirmDeleteDialog.show() confirmDeleteDialog.show()
} }