diff --git a/packages/dom/src/renderDOMHead.ts b/packages/dom/src/renderDOMHead.ts index f19c0f4a..3247b4e8 100644 --- a/packages/dom/src/renderDOMHead.ts +++ b/packages/dom/src/renderDOMHead.ts @@ -90,11 +90,11 @@ export async function renderDOMHead>(head: T, options: Ren } // we need to attach event listeners as they can have side effects such as onload for (const [k, value] of Object.entries(tag._eventHandlers || {})) { - // avoid overriding - ;(tag!.tag === 'bodyAttrs' ? dom!.defaultView! : $el)!.addEventListener( - k.replace('on', ''), - value.bind($el), - ) + if ($el.getAttribute(`data-${k}`) !== '') { + // avoid overriding + (tag!.tag === 'bodyAttrs' ? dom!.defaultView! : $el).addEventListener(k.replace('on', ''), value.bind($el)) + $el.setAttribute(`data-${k}`, '') + } } Object.entries(tag.props).forEach(([k, value]) => { const ck = `attr:${k}` diff --git a/test/unhead/dom/eventHandlers.test.ts b/test/unhead/dom/eventHandlers.test.ts index b59ae777..988e287c 100644 --- a/test/unhead/dom/eventHandlers.test.ts +++ b/test/unhead/dom/eventHandlers.test.ts @@ -20,7 +20,7 @@ describe('dom event handlers', () => { expect(await useDelayedSerializedDom()).toMatchInlineSnapshot(` " - +
diff --git a/test/unhead/dom/useScript.test.ts b/test/unhead/dom/useScript.test.ts index b385681d..4608a5f4 100644 --- a/test/unhead/dom/useScript.test.ts +++ b/test/unhead/dom/useScript.test.ts @@ -13,7 +13,7 @@ describe('dom useScript', () => { expect(await useDelayedSerializedDom()).toMatchInlineSnapshot(` " - +
diff --git a/test/vue/dom/events.test.ts b/test/vue/dom/events.test.ts index 604f5ecb..49588b41 100644 --- a/test/vue/dom/events.test.ts +++ b/test/vue/dom/events.test.ts @@ -28,7 +28,7 @@ describe('vue events', () => { " - +

hello world