Skip to content

Commit

Permalink
Allow client to retry RTLTextPlugin load after NetworkError (#9489)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Hamley committed Apr 2, 2020
1 parent 274d215 commit d912efb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions debug/rtl.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
<script src='/dist/mapbox-gl-dev.js'></script>
<script src='/debug/access_token_generated.js'></script>
<script>
var pluginURL = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js';
// badPluginURL allows us to simulate a NetworkError that we can recover from by retrying plugin loading
var badPluginURL = 'http://localhost:9966/debug/2762.html';
var goodPluginURL = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js';
var map = window.map = new mapboxgl.Map({
container: 'map',
zoom: 16.5,
Expand All @@ -40,13 +42,19 @@
});

document.getElementById('loadSync').onclick = function() {
mapboxgl.setRTLTextPlugin(pluginURL);
mapboxgl.setRTLTextPlugin(goodPluginURL);
};

document.getElementById('loadAsync').onclick = function() {
mapboxgl.setRTLTextPlugin(pluginURL, function(err) {
mapboxgl.setRTLTextPlugin(badPluginURL, function(err) {
if (err) {
throw err;
mapboxgl.setRTLTextPlugin(goodPluginURL, function (err) {
if (err) {
throw err;
} else {
console.log('rtl-text-plugin retry loaded successfully');
}
});
} else {
console.log('rtl-text-plugin loaded successfully');
}
Expand Down
5 changes: 5 additions & 0 deletions src/source/rtl_text_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ let pluginStatus = status.unavailable;
let pluginURL = null;

export const triggerPluginCompletionEvent = function(error: ?Error) {
// NetworkError's are not correctly reflected by the plugin status which prevents reloading plugin
if (error && typeof error === 'string' && error.indexOf('NetworkError') > -1) {
pluginStatus = status.error;
}

if (_completionCallback) {
_completionCallback(error);
}
Expand Down

0 comments on commit d912efb

Please sign in to comment.