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

(Re)introduce <svelte:document>? #3310

Closed
danburzo opened this issue Jul 29, 2019 · 13 comments · Fixed by #7149
Closed

(Re)introduce <svelte:document>? #3310

danburzo opened this issue Jul 29, 2019 · 13 comments · Fixed by #7149

Comments

@danburzo
Copy link

Is your feature request related to a problem? Please describe.

I noticed Svelte used to have a <svelte:document> but then it got removed. However, listeners on document work a bit differently than on document.body. For example, a mousemove / mouseup event on document.body stops the minute you move the cursor out of the browser viewport, but on document they keep getting fired.

Describe the solution you'd like

A <svelte:document> element to work with events on the Document object (especially events that happen exclusively on a document).

Describe alternatives you've considered

You can add events to document imperatively, but a declarative alternative would be nicer.

How important is this feature to you?

I've just started exploring Svelte, so I've not tried many things in it. For my particular usecase I would not be able to use <svelte:document> but, for the sake of completeness, I think it would be a good addition.

@Conduitry
Copy link
Member

As described in the linked ticket, <svelte:document> was removed because there were inconsistencies in mouse events between browsers. We don't want to be in the business of normalizing events.

There's nothing really in the way of adding this again, but the question is whether it would cause more confusion than it's worth. Even if we mention in the docs the differences between the events emitted in different browsers, issues will almost certainly be opened about Svelte 'bugs' in certain browsers or about feature requests to make it behave the same across browsers.

@danburzo
Copy link
Author

We don't want to be in the business of normalizing events.

I agree, I think it's great that Svelte aims to work with the DOM, warts and all. But the warts include the caveats around onmouseenter / onmouseleave on document, and they're hardly the only areas where browser implementations disagree.

Having <svelte:window> and <svelte:body> as proxies to attach events to their DOM counterparts makes not having <svelte:document> a curious omission. I feel like it's at the same level of convenience as the other <svelte:x> elements.

That being said, <svelte:document> can definitely wait until there are more use cases it can help with.

Thank you for considering it!

@freedmand
Copy link

<svelte:document> would be useful for implementing selectionchange events, which operate on the document. Please reconsider adding it, as browser inconsistencies for mouse events are outside of Svelte's control anyways

@naorye
Copy link

naorye commented Mar 24, 2020

So at the current status, if I'd like to add event listener to document (for example, listen to visibility change), the only option have is document.addEventListener / removeEventListener?

@antony
Copy link
Member

antony commented Mar 25, 2020

@naorye right now, yes, unless you can use an event from <svelte:window>

@tnguyen14
Copy link

That being said, svelte:document can definitely wait until there are more use cases it can help with.

I think visibilitychange is a good use case to reintroduce svelte:document?

@finnbear
Copy link

finnbear commented Nov 5, 2020

Another document-only API that I need is Pointer Lock: https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API

Specifically, I need document's onpointerlockchange, onpointerlockerror, and pointerLockElement

Please introduce <svelte:document> even if you don't support binding to the problematic mouse events.

@mustafa0x
Copy link
Contributor

Another: https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenchange_event

@sharpcodepro
Copy link

One more use case is Cordova/Ionic. These frameworks have Device Ready event, which fires on document object only. It would be really great to see svelte:document back. I can understand the reasons why it was removed but there are quite legitimate use cases for it.

@aradalvand
Copy link

aradalvand commented Jun 20, 2021

Any updates? I don't think implementing this would take too much time and effort, since we used to have it in the past.
So, can't you just bring back the old code for this and also keep <svelte:body>? What would be wrong with that?

@Crisfole
Copy link
Contributor

I think the solution to this is to lean on the 'warnings' API for problematic events; this is already something you do with A11y warnings...

@mustafa0x
Copy link
Contributor

Another reason: iOS rarely fires window.onmousedown, so document.onmousedown has to be used.

dummdidumm added a commit that referenced this issue Mar 15, 2023
Closes #3310

---------

Co-authored-by: Ben McCann <[email protected]>
Co-authored-by: Simon H <[email protected]>
@Conduitry
Copy link
Member

<svelte:document> is now available in 3.57.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.