diff --git a/library/src/plugins/actions/fetch.ts b/library/src/plugins/actions/fetch.ts index 046f149b..10a2122b 100644 --- a/library/src/plugins/actions/fetch.ts +++ b/library/src/plugins/actions/fetch.ts @@ -243,12 +243,15 @@ const dispatchFetch = ( type: string, el: HTMLOrSVG, argsRaw: Record, -) => - document.dispatchEvent( +) => { + const dispatchEl = el.isConnected ? el : document + dispatchEl.dispatchEvent( new CustomEvent(DATASTAR_FETCH_EVENT, { detail: { type, el, argsRaw }, + bubbles: true, }), ) +} const isWrongContent = (err: any) => `${err}`.includes('text/event-stream') diff --git a/library/src/plugins/attributes/on.ts b/library/src/plugins/attributes/on.ts index 9688f7f7..13dc8abd 100644 --- a/library/src/plugins/attributes/on.ts +++ b/library/src/plugins/attributes/on.ts @@ -51,7 +51,6 @@ attribute({ const eventName = modifyCasing(key, mods, 'kebab') // Listen for Datastar events on the document if ( - eventName === DATASTAR_FETCH_EVENT || eventName === DATASTAR_SIGNAL_PATCH_EVENT ) { target = document