Page MenuHomePhabricator

wikipage.content fired twice on RecentChanges with live updates
Closed, InvalidPublic

Description

  1. Add something like
mw.hook( 'wikipage.content' ).add( function() {
	'use strict';
	console.log( 'wikipage.content fired' );
} );

to Special:MyPage/common.js

  1. Make sure you have not disabled the new RecentChanges at Special:Preferences#mw-prefsection-rc
  1. Open the console
  1. Go to Special:RecentChanges
  1. Click on Live updates

It should be clear from the timing that wikipage.content is fired twice every time a new element is added.

Screenshot:

wikipage content fired twice with live updates cropped.png (463×1 px, 101 KB)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The hook callback receives $elements as the first arguments. It is fired once with the new list of changes as $elements and once with the updated options form.

If you have a user script that enhances any of these parts, you can inspect $elements to check if it's appropriate for it to run.

Ah, I see! So I have to change my code to

mw.hook( 'wikipage.content' ).add( function( elements ) {
	'use strict';
	if ( elements.hasClass( 'mw-changeslist' ) ) {
		console.log( 'wikipage.content fired' );
	}
} );

Thank you!