resourceloader: Add forward-compat to startup.js for I1c995a9572d
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 8 May 2019 17:21:40 +0000 (18:21 +0100)
committerCatrope <roan@wikimedia.org>
Wed, 8 May 2019 21:18:31 +0000 (21:18 +0000)
This prepares startup.js to support the declarative format
for transporting values for mw.config, mw.loader.state, and
mw.loader.load.

These are currently applied as executable code in <head>, but after
I1c995a9572d these will instead be declarative allowing them
to be set without a closure and consolidating control over the
startup flow to startup.js.

We'll still have RLQ for two reasons: 1) compat with cached HTML,
and 2) for the use case of streaming load.php-like responses
as part of the HTML payload (e.g private modules, previews,
inline snippets).

Change-Id: I76a2c8d52fa782cd09d48d99b5fbb7be35e2b9a8

resources/src/startup/startup.js

index f2d964a..063ea09 100644 (file)
@@ -118,12 +118,26 @@ if ( !isCompatible( navigator.userAgent ) ) {
                $CODE.registrations();
 
                mw.config.set( $VARS.configuration );
+               // For the current page
+               mw.config.set( window.RLCONF || {} );
+               mw.loader.state( window.RLSTATE || {} );
+               mw.loader.load( window.RLPAGEMODULES || [] );
 
-               // Process callbacks for Grade A
+               // Process RLQ callbacks
+               //
+               // The code in these callbacks could've been exposed from load.php and
+               // requested client-side. Instead, they are pushed by the server directly
+               // (from ResourceLoaderClientHtml and other parts of MediaWiki). This
+               // saves the need for additional round trips. It also allows load.php
+               // to remain stateless and sending personal data in the HTML instead.
+               //
+               // The HTML inline script lazy-defines the 'RLQ' array. Now that we are
+               // processing it, replace it with an implementation where 'push' actually
+               // considers executing the code directly. This is to ensure any late
+               // arrivals will also be processed. Late arrival can happen because
+               // startup.js is executed asynchronously, concurrently with the streaming
+               // response of the HTML.
                var queue = window.RLQ;
-               // Replace RLQ placeholder from ResourceLoaderClientHtml with an implementation
-               // that executes simple callbacks, but continues to store callbacks that require
-               // modules.
                window.RLQ = [];
                /* global RLQ */
                RLQ.push = function ( fn ) {