dom-expressions icon indicating copy to clipboard operation
dom-expressions copied to clipboard

Is it possible to bind event to rootElement ?

Open chenzn1 opened this issue 1 year ago • 2 comments

Background

https://github.com/solidjs/solid/issues/1786 event. stopPropagation is not work as expected.

Solution

Change the render and delegateEvents in dom-expressions/src/client.js

let ROOT_ELEMENT = window.document
export function render(code, element, init, options = {}) {
  ROOT_ELEMENT = element
}

export function delegateEvents(eventNames, document = ROOT_ELEMENT) {
}

Code location

chenzn1 avatar Jun 22 '23 03:06 chenzn1

That would be a very specific and arbitrary solution for the render function, and not flexible across multiple render() calls.

The concept of delegation should be totally decoupled from exactly which element we render to. We might like delegation to be on any arbitrary node besides the one we render to.

I also mentioned in

  • https://github.com/solidjs/solid/issues/1786

that not delegating by default would be great.

trusktr avatar Aug 26 '23 17:08 trusktr

Event delegation is important for portals and pre-emptive hydration techniques. I think it might be possible for Portals to have a different delegation approach(I believe React did something like this for React 17) but this is definitely something that is involved. Especially considering multiple/render hydration entries in things like Islands.

ryansolid avatar Oct 09 '23 22:10 ryansolid