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.

State sometimes change twice after one change

See original GitHub issue

Do you want to request a feature or report a bug?

BUG

What’s the current behavior?

https://jsfiddle.net/31tb8gyx/30/

Select some text and click bold button, and you will see the onChange event fired twice, and as a result, the history state of editor is undesierable.

This issue happens only when call e.preventDefault in onMouseDown handler, but without e.preventDefault, the editor would blur and user could not continue editing, which is also too bad.

  • OS: MacOS
  • Browser: Chrome
  • Slate: 0.28.2

What’s the expected behavior?

No twice state change, no unnecessary rerender, the history state should be clean.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ianstormtaylorcommented, Oct 30, 2017

@chemzqm I’m still not clear on what you are talking about. If you change the undo handler to be onMouseDown, then there’s no issue with undoing.

0reactions
ianstormtaylorcommented, Oct 31, 2017

@isubastiCadmus sounds like it’s definitely possible, I’d accept a PR that fixes that checking logic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React component sometimes renders twice with unchanged ...
The answer is that React uses a set of heuristics to determine whether it can avoid calling the rendering function again.
Read more >
Calling setState multiple times in hooks causes the previous ...
It only works if setState is called synchronously (which is often not the case). // Otherwise your change to "foo" will be overridden...
Read more >
React state batch updating - reduce re-renders | The Startup
We change the state by calling setState or using useState . These changes cause parts of the component to re-render, and possibly to...
Read more >
Why React doesn't update state immediately - LogRocket Blog
When developing React applications, you may have noticed that state updates don't immediately reflect new values after being changed.
Read more >
React state not updating immediately? - Daggala
The state remains constant inside the render but can be changed between two renders. The same goes for dispatch and useReducer. we could...
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