Page MenuHomePhabricator

mw.notify() has a non-intuitive return value
Closed, ResolvedPublic

Description

mw.notify() is implemented as:

mw.notify = function ( message, options ) {
	// Lazy load
	return mw.loader.using( 'mediawiki.notification', function () {
		return mw.notification.notify( message, options );
	} );
};

Since a callback is used here instead of .then() chaining, the return value of the function is a promise wrapping over an internal RL function.

Expected return value: promise wrapping over a Notification object.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Krinkle triaged this task as Medium priority.Jun 5 2023, 6:52 PM
Krinkle added a project: patch-welcome.
Krinkle moved this task from Inbox to Confirmed Problem on the MediaWiki-ResourceLoader board.
Krinkle subscribed.

Thanks @SD0001. The existence of the return statement here makes me fairly certain this is a bug. As you say, right now it's returning the parent promise, which resolves to void. The inner one goes nowhere.

Tracing this in git blame, leads to https://gerrit.wikimedia.org/r/c/mediawiki/core/+/583754 (T233676) in which the me of 2020 was overly clever in saving bytes by changing from what it should be, return using().then( => return ), to the shortcut of return using(, => return ).

Would you be interested in writing a patch for this, @SD0001?

Change 927251 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/core@master] mediawiki.base: tweak mw.notify() return value

https://gerrit.wikimedia.org/r/927251

Change 927251 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.base: tweak mw.notify() return value

https://gerrit.wikimedia.org/r/927251

matmarex subscribed.