diff --git a/src/core/drive/morph_renderer.js b/src/core/drive/morph_renderer.js index 2c5d14874..2ebe9021e 100644 --- a/src/core/drive/morph_renderer.js +++ b/src/core/drive/morph_renderer.js @@ -41,7 +41,18 @@ export class MorphRenderer extends PageRenderer { } #shouldAddElement = (node) => { - return !(node.id && node.hasAttribute("data-turbo-permanent") && document.getElementById(node.id)) + if (node.id && node.hasAttribute("data-turbo-permanent") && document.getElementById(node.id)) { + return false; + } else { + const event = dispatch("turbo:before-add-element", { + cancelable: true, + target: node, + detail: { + newElement: node + } + }); + return !event.defaultPrevented; + } } #shouldMorphElement = (oldNode, newNode) => {