fix Safari 13 addEventListener on MediaQueryList #67
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "main"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Please accept this PR that fixes an error on Safari 13 because addEventListener is not available yet on MediaQueryList.
see https://github.com/mdn/sprints/issues/858 for more description of the issue
onPrintactually looks at its event argument. I don't see any mention of such an object being passed toaddListenercallbacks in https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener . Are you sure the patch works the way you wrote it? (I don't have a Safari 13 around to test.)That's the fastest PR review I have ever seen in the whole FOSS world!
I didn't test that it actually works when the print is triggered. Is it what this code is doing?
I was more concerned about having the code execute in general (the whole codemirror was broken because of that).
I have read the code though, and it should work.
I can see we get an argument that looks exactly the same as the one received in the newer API
addEventListener:It has a
matchesboolean and inherits atypefrom Event.And yes, the old API
addListenerdoesn't take a type parameter like the new one does (with "change" value)If you look at the commits of other people who solved this before us, they did exactly like what I propose.
https://github.com/h2oai/wave/pull/394/files
I have checked with a
console.log(event)at the beginning ofonPrintand this is what I get:when print is triggered:
when the print is finished:
so I believe that your guard
if (event.type == "change" && !(event as MediaQueryListEvent).matches) returnis never going to be useful on Safari 13, but tha's ok, right?The print works fine.
BTW, you can also test on your end, as the old API is available on all browsers.
Some people have even solved this issue by always using the old API
addListenerhere in this case of media queries, even if it is deprecated.I've merged this and followed up with a patch that makes the listener ignore
matches: falseobjects.very nice! do you know when the next release to npm will be?
I've tagged 6.29.1
ok thanks. let me try to come back to a normal dependency tree using the new npm package, and see if it catches that newest version.
All is good ! thanks for your timely fix