Krinkle has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/378804 )
Change subject: ext.eventLogging.subscriber: Don't wait for "load" if it
already happened
......................................................................
ext.eventLogging.subscriber: Don't wait for "load" if it already happened
On wikis with jQuery 3 enabled, I noticed it sometimes prints this warning:
> JQMIGRATE: jQuery(window).on('load'...) called after load event occurred
Given "load" is an event, and given browsers don't fire event handlers
retroactively, this means on those page views, we end up never subscribing to
mw.track events.
https://github.com/jquery/jquery-migrate/blob/c12e1ab6/warnings.md
This isn't a regression in jQuery 3, but they do add a nice warning
as of this version to detect this common mistake.
Note that $()/$(document).ready() isn't affected because those handlers
are Promise-based (which always trigger callbacks retroactively if said
Promise is already resolved).
Fix this by checking for document.readyState and based on that if the
event has already happened, queue init() as the next thing (via rIC).
Bug: T169385
Change-Id: I774ea6880f3463c606b1d45f9cb60bfb6c5a2617
---
M modules/ext.eventLogging.subscriber.js
1 file changed, 20 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventLogging
refs/changes/04/378804/1
diff --git a/modules/ext.eventLogging.subscriber.js
b/modules/ext.eventLogging.subscriber.js
index 28ea1b7..4a241bb 100644
--- a/modules/ext.eventLogging.subscriber.js
+++ b/modules/ext.eventLogging.subscriber.js
@@ -39,6 +39,14 @@
}
/**
+ * @private
+ * @ignore
+ */
+ function init() {
+ mw.trackSubscribe( 'event.', handleTrackedEvent );
+ }
+
+ /**
* This a light-weight interface intended to have no dependencies and be
* loaded by initialisation code from consumers without loading the rest
* of EventLogging that deals with validation and logging to the server.
@@ -87,14 +95,17 @@
};
- // Avoid the logging of duplicate events (T170018).
- //
- // The load event must only fire once. However, Firefox 51 introduced a
- // bug that causes the event to fire again when returning from the
- // "Back-Forward cache" (BFCache) under certain circumstances (see
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1379762).
- $( window ).one( 'load', function () {
- mw.trackSubscribe( 'event.', handleTrackedEvent );
- } );
+ // It's possible for this code to run after the "load" event has
already fired.
+ if ( document.readyState === 'complete' ) {
+ mw.requestIdleCallback( init );
+ } else {
+ // Avoid the logging of duplicate events (T170018).
+ //
+ // The load event must only fire once. However, Firefox 51
introduced a
+ // bug that causes the event to fire again when returning from
the
+ // "Back-Forward cache" (BFCache) under certain circumstances
(see
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1379762).
+ $( window ).one( 'load', init );
+ }
}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/378804
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I774ea6880f3463c606b1d45f9cb60bfb6c5a2617
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits