Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event issues with portals and considering a rework of how handlers are installed #2154

Closed
1 of 4 tasks
WorldSEnder opened this issue Nov 18, 2021 · 0 comments · Fixed by #2510
Closed
1 of 4 tasks
Labels

Comments

@WorldSEnder
Copy link
Member

WorldSEnder commented Nov 18, 2021

Problem
Currently, the event handlers are installed on the global document. This mirrors how react used to do it before v17.0, see also the relevant issue on their side: facebook/react#2043. This is similar to #1564 but more geared towards a correct portal implementation (and might have one-solution-to-close-them-all).

To summarize the issues with current behavior:

  • Multiple roots, as implemented with portals Implementation of portals #2147, can fail to propagate events correctly. I've not thought of this when I wrote the impl, here's my current understanding:
    • Events fired inside the shadow dom propagate up to the shadow dom until they reach the shadow root, and then change their target to point to the element containing the shadow dom. Thus when they are captured by the installed delegate listener on document, they are dropped, because yew thinks the event was fired on the outer shadow host, not the inside.
    • Events fired inside an iframe stop propagating at the inner document (and never reach the delegate)
  • Running multiple instances on the same page does not always work as expected. I have not experienced this myself, but consider if one instance stops the propagation of a captured element, it's stopped in the other one as well

Things to worry about when addressing this issue:

How to address this

I think the most straight forward way is to pass down, in VDiff, the outermost host element, in which yew renders and target that for event listeners instead of document.body. Then, the host elements of portals also count as host elements and register for events.

Steps To Reproduce
I will edit this with a reproduction issue, when I'm done with this.

Expected behavior
Events should work in shadow dom and other circumstances. The listeners should be registered on elements hosting yew components, not at the document root.

Environment:

  • Yew version: master

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I would like to fix this, but I'm unsure about the scope of work here :)
  • I don't have time to fix this right now, but maybe later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant