web icon indicating copy to clipboard operation
web copied to clipboard

Allow setting an event handler to null

Open navaronbracke opened this issue 1 year ago • 3 comments

I was looking into package:web to reevaluate if it fixes an old bug related to fullscreen events that has been in dart:html for a little while. (it does fix it!)

While investigating that, I noticed you could not unset the fullscreen change event handler, once you no longer need it.

It requires a JSFunction, not a JSFunction? https://github.com/dart-lang/web/blob/21ef7a23d17b25c8721f69bb67cbc41235ffa545/lib/src/dom/dom.dart#L565C3

This idea can probably be applied to every JS event handler that follows a similar pattern?

navaronbracke avatar Jul 07 '23 10:07 navaronbracke

It's declared as non-nullable here: https://github.com/w3c/webref/blob/1f2f1061b6496aae3e6886314a5778c4465c4022/ed/idl/fullscreen.idl#L29 and https://fullscreen.spec.whatwg.org/#api. I'm not sure why these getters and setters are non-nullable even though addEventListener can accept a null event listener.

srujzs avatar Sep 21 '23 18:09 srujzs

And EventHandler is a typedef that's nullable: typedef EventHandlerNonNull? EventHandler;

https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler

https://github.com/w3c/webref/blob/b1f1d969e12f0342d7b0b008352832016c9e6e2a/ed/idl/html.idl#L2074

But not here:

https://github.com/dart-lang/web/blob/819f8b454ca331d1cadda54a86572743e48547ad/lib/src/dom/html.dart#L90

denniskaselow avatar Sep 22 '23 14:09 denniskaselow

That is indeed a bug in how we handle typedefs, thanks!

A fix has been landed here: https://github.com/dart-lang/web/pull/79.

srujzs avatar Sep 27 '23 22:09 srujzs