Page MenuHomePhabricator

MarkAsHelpful: Don't use global delegate event handlers
Closed, DeclinedPublic

Description

Follows-up T69356.

The usage of live() was mitigated by using a global delegate selector (which is what "live()" did internally). That'll keep it working, but really it shouldn't be using that in the first place.

jQuery.live was deprecated because it masked the fact that it added a global event handler and matched every node from a user event against a css selector.

By being forced to use $(document).on('click', selector, fn) it emphasises that this is a global listener and is intended to encourage you to instead re-evaluate what this code is doing.

It should probably be listening on a common parent much lower down the tree than the document root.

I suspect that maybe this doesn't even have to be a delegate handler at all. It seems MarkAsHelpful does make assumptions about the matched node (it calls .parent().parent()).

If MarkAshelpful really does add new links asynchronously after document ready,, it should listen on a common ancestor instead.

If it doesn't and the live() was just an overambitious oversight, then it can be swapped for a regular query with on('click', fn).


Version: unspecified
Severity: normal

Details

Reference
bz67738

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 22 2014, 3:30 AM
bzimport set Reference to bz67738.
bzimport added a subscriber: Unknown Object (MLST).

[Setting lowest priority as this extension isn't deployed anymore according to bug 67772 comment 1]

[Setting lowest priority as this extension isn't deployed anymore according to bug 67772 comment 1]

Per T69772 (bug 67772) MarkAsHelpful is actually still deployed and even globally enabled.

Confirmed in wmf-config:
https://github.com/wikimedia/labs-incubator/blob/9203fd3e7a/CommonSettings.php#L327

// MarkAsHelpful
require_once("$ext/MarkAsHelpful/MarkAsHelpful.php");
Krinkle raised the priority of this task from Lowest to Medium.May 13 2015, 1:20 PM
Krinkle set Security to None.
Krinkle updated the task description. (Show Details)
Krinkle removed a subscriber: Unknown Object (MLST).

Should this be just declined now, this is probably now not deployed?