Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow client to retry RTLTextPlugin load after NetworkError #9489

Merged
merged 3 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
asheemmamoowala marked this conversation as resolved.
Show resolved Hide resolved
// 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