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

Race condition on first run causes disabled UI #24

Open
irnc opened this issue Sep 19, 2019 · 1 comment
Open

Race condition on first run causes disabled UI #24

irnc opened this issue Sep 19, 2019 · 1 comment
Labels

Comments

@irnc
Copy link
Contributor

irnc commented Sep 19, 2019

Sometimes message listener inside iframe's map.js module is added after message is sent from exercise.js (almost constantly reproducible in incognito mode). This race condition causes message not processed and thus callback not called. The callback is essential to UI as it removes disabled state from Run Query button.

Analysis

First we send answer query, on response we set answer received flag and update map, which sends a second query, that time using code from the editor.

onload: function() {
exercise.query(exerciseAnswer);

onSuccessData: function(data){
if(answer === null) {
if( data.query === exerciseAnswer ) {
answer = processAnswer(escapeHTML(data.resultText));
exercise.updateMap();
}
return;
}

updateMap: function(){
if(!pending_query) {
pending_query = true;
postTo(iframe, 'update_map', [cm.getValue()]);
}
},

Response from that second query activates UI, in particular the Run Query button. Without this button it is not possible to send query again, so there is no workaround for this issue.

if(firstRun) {
firstRun = false;
classie.add(editorCover, "hide");
classie.remove(runBtn, "disabled");
classie.remove(resetBtn, "disabled");
// firstRun should not produce errors
return;
}

Root cause

Message listener inside iframe's map.js module is added on $.ready handler. Message is sent from exercise.js from iframe's onload handler.

load event is first fired in iframe context, and only then in parent, i.e. LearnOverpass. But because $.ready handler is called asynchronously, listener is added after message is posted, causing message going unprocessed.

$.ready handler is called asynchronously starting jQuery 3.0.0 released June 9, 2016. This was a breaking change, so issue started to manifest itself only after overpass-turbo's map switched to jQuery ^3.0.0 at February 6, 2018.

@irnc
Copy link
Contributor Author

irnc commented Sep 19, 2019

Workaround

Until this issue is fixed, please use LearnOverpass in non-incognito mode and refresh page when Run Query button is disabled on initial page load.

@irnc irnc added the bug label Sep 20, 2019
@irnc irnc pinned this issue Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant