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 handlers held up by await in another handler? #6000

Open
sjml opened this issue Feb 18, 2021 · 2 comments
Open

Event handlers held up by await in another handler? #6000

sjml opened this issue Feb 18, 2021 · 2 comments

Comments

@sjml
Copy link

sjml commented Feb 18, 2021

Describe the bug
I'm seeing unexpected (to me) ordering of event handlers, and while the bug could be in my understanding rather than Svelte, I'd still like to correct it if that's the case.

To Reproduce
I've set up a small repro in this REPL. If you click outside the blue div, you'll see a series of messages that ends with "outside." If you click inside it, you'll see "inside." But if you click directly on the chevron, it will still show "outside" because by the time the click handler is looking at it, it's been removed from the DOM by the conditional layout.

Expected behavior
In the bigger picture I'm trying to detect clicks outside of the colored div, and that can be accomplished in other ways, but I'm struggling to understand what's happening in the event loop here. By await-ing a tick() in the buttonClickHandler function, my understanding is that the body's click handler should get called before control returns to the button's. But if you look at the console, the button swap is happening before the body click.

(The outcome here is that by the time the body click is looking at it's target, it's already been removed from the DOM, and so we can't meaningfully investigate it's place in the hierarchy.)

Severity
This is more annoying and puzzling than problematic... there are easy workarounds for what I'm actually trying to accomplish, but I want to make sure my mental models of await and the event loop are correct.

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 27, 2021
@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants