ProfessionalWiki / Maps

🗺 Maps is the MediaWiki extension that enables visualization of geographic data with dynamic embedded maps.
https://maps.extension.wiki
Other
73 stars 61 forks source link

Leaflet's CSS not loaded properly when rendering page with action=parse #630

Closed Ostrzyciel closed 4 years ago

Ostrzyciel commented 4 years ago

Setup

Issue

Displaying maps using Leaflet works fine in most cases, the problem arises when one uses API's action=parse method. It can (and will) return the required ResourceLoader modules that can be then loaded by client JS when displaying the parsed wikitext to the user. After doing that (and triggering the appropriate wikipage.content JS hook) the Leaflet map loads, but most CSS is missing, leaflet.css is not loaded for sure.

This exact method of parsing and displaying parsed wikitext is used by core's live preview feature and probably quite a few gadgets.

After doing a quick code search I think what's causing this is the fact that Leaflet's CSS is loaded somehow in LeafletService.php, not using ResourceLoader, which means action=parse has no way of knowing about this CSS: https://github.com/JeroenDeDauw/Maps/blob/d35b5e9cb90035d97dc07a839068c3b88c97fe29/src/LeafletService.php#L205

Steps to reproduce the observation:

  1. Go to Special:Preferences, Editing tab and enable the Show previews without reloading the page option.
  2. Go to https://sandbox.semantic-mediawiki.org/wiki/Maps_using_templates_-_leaflet
  3. Open the source editor for this page and click Show preview
  4. The map should appear garbled with tiles out-of-order.
Ostrzyciel commented 4 years ago

I just tried walking around this issue by loading the said CSS file manually through JS, it works perfectly.

So the question is – can this CSS file be loaded with ResourceLoader somehow instead of the current solution (that I admittedly don't uderstand :P)?

JeroenDeDauw commented 4 years ago

This file is no longer loaded via resource loader due to https://github.com/JeroenDeDauw/Maps/issues/607

If this https://phabricator.wikimedia.org/T249129#6053125 works then we can switch back to using resource loader.

JeroenDeDauw commented 4 years ago

@Ostrzyciel a PR is definitely welcome