From 2c23c564e37320f99a4be0f77c954e910b38eaa6 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 8 May 2019 18:21:40 +0100 Subject: [PATCH] resourceloader: Add forward-compat to startup.js for I1c995a9572d 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 , 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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/resources/src/startup/startup.js b/resources/src/startup/startup.js index f2d964a1c1..063ea09612 100644 --- a/resources/src/startup/startup.js +++ b/resources/src/startup/startup.js @@ -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 ) { -- 2.20.1