question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best practice suggestion: display should reflect the slate.value model under (simulated) lag

See original GitHub issue

Please consider the following fiddle: link

I’ve set a setTimeout of 500ms to simulate a stressed computation load.

onChange({ value }) {
    setTimeout(() => {
    	this.setState({ value });
    }, 500);
  }

In the first video i’ve type 1-9 quickly (less than 0.5 per key). the final text in a normal stress would have been “123456789”

kon8bnnoq1

In the second video i’ve long key pressed the right arrow key, moving the cursor from the start of the sentence it its end.

axs5gz58qq

What’s the expected behavior?

Safe to say, lagged responsiveness is expected. But the UI should only display events that are stored to state.value. In the first examples, digit “1” should have not been temporarily displayed as it was not stored in the final state.value. In the second example, the cursor should have not move forward and jump back to what was stored in the state.value. It should have moved very slowly.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
schneidmastercommented, Feb 4, 2018

Well, it’s the same thing. The state.value in the wrapping component is what’s given to the value prop so it’s also the value inside the slate editor to which the change is applied. It’s just that in your example, the first state.value update does not happen for 500ms, so any subsequent changes that happen within that 500ms will be based on the non-updated state.value. In other words, the fact that the onChange has been called does not mean that the wrapping component’s state has been updated; with your setTimeout the wrapping component’s state will not actually be updated for 500ms.

1reaction
schneidmastercommented, Feb 3, 2018

Gotcha. So that’s actually already the behaviour in Slate. Keeping with the rapid-fire 1, 2, 3 from my last comment, consider this example timeline:

Time Description Current state.value
0ms initial state ''
5ms 1 pressed, and queues a setTimeout in 500ms ''
10ms 2 pressed, and queues a setTimeout in 500ms ''
15ms 3 pressed, and queues a setTimeout in 500ms ''
505ms The setTimeout from 1 fires and updates the state.value, Slate rerenders '1'
510ms The setTimeout from 2 fires and updates the state.value, Slate rerenders '2'
515ms The setTimeout from 3 fires and updates the state.value, Slate rerenders '3'

In essence, the flashing mirrors the amount of time between keypresses. At 505ms, Slate receives a new value prop saying the value is now '1'. Slate rerenders to match what is then the current state.value. It has no way of knowing that another setTimeout is going to resolve again in a few ms and change the state again. Indeed, the flashing happens because Slate already does exactly what you suggest (precisely render what is provided in its value prop).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best Practices for Operation and Maintenance of Photovoltaic ...
A best practice is to run a slip sheet continuously under rack members to avoid ... yet they should reflect the factors that...
Read more >
Lag time between state-level policy interventions and change ...
Here, we study the lag time between policy interventions and change in COVID-19 ... a probabilistic approach could be relevant to model the...
Read more >
Performance Guidelines for Mobile Devices in Unreal Engine
Optimizing content and features for mobile games.
Read more >
An Introduction to Smart Contracts and Their Potential and ...
Below, we outline the background and functions of smart contracts, discuss whether they can be deemed enforceable legal agreements under ...
Read more >
Technology readiness levels for machine learning systems
The development and deployment of machine learning systems can be ... yet much of the value in practice is realized in the transitions: ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found