ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
858 stars 125 forks source link

Is it possible to bind event to rootElement ? #263

Open chenzn1 opened 1 year ago

chenzn1 commented 1 year ago

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

trusktr commented 1 year ago

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

that not delegating by default would be great.

ryansolid commented 11 months ago

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.