nearby.js conditionalizes the options passed to the Nearby constructor. However, it doesn't wait for the Promise to return.
function refresh( opt ) { // check, if the api object (options.api) is already created and set if ( options.api === undefined ) { // decide, what api module to use to retrieve the pages if ( endpoint ) { // BUG loader.using( 'mobile.foreignApi' ).then( function () { var JSONPForeignApi = M.require( 'mobile.foreignApi/JSONPForeignApi' ); options.api = new JSONPForeignApi( endpoint ); } ); // /BUG } else { options.api = new mw.Api(); } } // make sure, that the api object (if created above) is added to the options object used // in the Nearby module opt = util.extend( {}, opt, options ); if ( !nearby ) { nearby = new Nearby( opt ); // todo: use the local emitter when refresh() doesn't recreate the // OO.EventEmitter by calling the super's constructor. M.on( NEARBY_EVENT_POST_RENDER, function () { var fragment = router.getPath(), el; if ( isFragmentIdentifier( fragment ) ) { // The hash is expected to be an identifier selector (unless the // user entered rubbish). el = nearby.$( '#' + fragment ); if ( el[0] && el[0].nodeType ) { $( window ).scrollTop( el.offset().top ); } } overlay.hide(); } ); } nearby.refresh( opt );
Steps to Reproduce
- Configure the Nearby endpoint to mirror enwiki: $wgMFNearbyEndpoint = 'https://en.wikipedia.org/w/api.php';.
- Visit http://localhost:8080/wiki/Special:Nearby
- Tap "show nearby articles."
Expected Results
- Nearby pages are shown.
Actual Results
- No pages are shown.
Uncaught TypeError: Cannot read property 'ajax' of undefined
at NearbyGateway._search (NearbyGateway.js?b33c9:110)
at NearbyGateway.getPages (NearbyGateway.js?b33c9:60)
at Nearby._find (Nearby.js?5ed3d:125)
at Nearby.refresh (Nearby.js?5ed3d:214)
at refresh (nearby.js?e72fd:95)
at nearby.js?e72fd:112
at matchRoute (oojs-router.js?f0f4f:29)
at Object.<anonymous> (oojs-router.js?f0f4f:94)
at Function.each (jquery.js?6a07d:360)
at Router.checkRoute (oojs-router.js?f0f4f:93)Environments Observed
- localhost
Browser Version
- Chromium v69.0.3497.81
OS Version
- Ubuntu v18.04
Device Model
- Desktop
Device Language
- English
Developer notes
This doesn't impact production. JSONPForeignApi is only used for development.
This appears to have been broken in T125820 as the code inside loader.using( 'mobile.foreignApi' ) is dead code in this respect.
loader.using( 'mobile.foreignApi' ).then( function () {
var JSONPForeignApi = M.require( 'mobile.foreignApi/JSONPForeignApi' );
// happens after nearby = new Nearby( opt ); is called so has no effect
options.api = new JSONPForeignApi( endpoint );
} );
nearby = new Nearby( opt );A fix would make sure this code runs before Nearby is created, or have it moved into Nearby itself.