205stelzear / elections

Website / Webapp to create and view elections for any Scout group
https://205stelzear-elections.v-ed.ca/
MIT License
0 stars 0 forks source link

The verification of setup inputs validity blocks the UI thread #75

Closed V-ed closed 4 years ago

V-ed commented 4 years ago

Currently, when you input candidates, you see a small delay between typing, making it feels like the application is lagging, while it is only doing an asynchronous request in the background, blocking the app from actually adding the inputs to the fields.

~To make the app more seamless, I should switch to an async method to prevent lockups.~

~The issue I see doing this is that the request should be canceled or some sort if the inputs' verify state gets changed (goes from invalid to valid or vice versa).~

TODOs

V-ed commented 4 years ago

I tried multiple ways of switching to async functions (the sendRequest method should in theory already be async for every single request, since it is done in a promise... weird), but I couldn't fix this issue (yet).

The issue is definitely happening when doing the request though, like if the UI thread was being locked, which I find weird. I'll investigate again sooner or later.

V-ed commented 4 years ago

I don't think I'll fix this issue properly since the request will always take up some time and lag the input field a bit.

Therefore, I'll see about changing the way I wait for the minimum delay and doing a hack instead. I added todos to the issue body.

These tweaks will make the inputs feel more natural, as currently, this is what is happening : the javascript engine is busy trying to do the request while the UI received a new command, which the thread can't execute since it is busy and the input event is therefore added to the event queue instead of executed immediately.

Further readings about Promise asynchronous behaviors :

V-ed commented 4 years ago

Changing the while loop to a calculated timeout actually fixes this issue right away, which is interesting.

I will still implement the input delayer for sending a request, as I don't want to spam send requests when typing quickly in any input field.

V-ed commented 4 years ago

I decided that the delay between inputs were to be 250ms, and the minimumDelay for showing a spinner for (both index's AND setup page) is now 150ms.

I think those values gives the best perceived performance while still not putting too much stress on my server.