Page MenuHomePhabricator

Improve bundling of mediawiki.watchstar.widgets and mediawiki.page.watch.ajax
Open, Needs TriagePublic

Description

Per codesearch, the only place that the mediawiki.watchstar.widgets ResourceLoader module is used is as a run-time dependency of the mediawiki.page.watch.ajax module (loaded via mw.loader.load and mw.loader.using when needed if watchlist expiry is enabled). I propose that the widget be merged into the watch module, unless there are plans to use it elsewhere. The widget was originally introduced to be used in the watch module, rMW6224ffd03ccf: Replace toast with OOUI popup on watchlist message / T249259: Watchlist Expiry: Update popup loading behavior when watching via star [medium], and I couldn't find references to any other uses in the past.

This could cause a minor performance hit if additional loading is needed for the dependencies of the widget that aren't being loaded immediately for the overall watch button. If this is an issue, we can make is so that the dependencies of the widget still only get loaded when needed by putting them in the mw.loader.load / .using calls instead of the widget itself, and having the widget code not be run until the dependencies are loaded.

Event Timeline

The mediawiki.page.watch.ajax bundle is small and loads on all page views. It is mainly responsible for initiating the watch process from the watchstar on click. Anything later is lazy-loaded for performance reasons, with the latency masked/hidden by the API request that happens at the same time.

The mediawiki.watchstar.widgets bundle requires the OOUI framework and is used to render the notification bar for changing the expiry after adding something to your watchlist. The OOUI framework and any other dependencies for this indeed should not be eagerly loaded on all page views.

The idea of loading a JS class that would crash if referenced too early seems fragile and would be a new pattern that we don't currently use anywhere in production. It's worth considering of course, but it's also important to look around if there are other ways to achieve it so as to avoid having to understand and maintain many ways to do the same thing.

A possible alternate reduction in the same general area might be:

  • Bundle mediawiki.page.watch.ajax with other small UI code that applies to most page views by most logged-in users. I don't see anything off-hand though, it might be that this is the only thing like it. We have already created bundles for stuff that applies to all users ("mediawiki.page.ready") and stuff that applies to non-default abilities (misc "curate", misc "pref").
  • Bundle some of the mediawiki.widgets.* solo class bundles based on common purpose or usage pattern.
mewoph subscribed.

Moving to Needs Discussion to determine if the Growth team should make these performance improvements to Watchlist

I suppose mediawiki.page.watch.ajax could lazy-load OOUI and then lazy-declare WatchlistExpiryWidget. Don't know if it's worth the effort.

Per discussion, the Growth team can't work on this in the near term.

The Community Tech team is open to review this task, it's a minor task

Krinkle renamed this task from Merge mediawiki.watchstar.widgets into mediawiki.page.watch.ajax to Improve bundling of mediawiki.watchstar.widgets and mediawiki.page.watch.ajax.Oct 5 2021, 6:30 PM
Krinkle moved this task from Limbo to Watching on the Performance-Team (Radar) board.