Bug(not sure): Strange ordering of setState calls

This issue has been created since 2022-09-11.

React version: 16

Steps To Reproduce

  1. Click the "Test App" div
  2. See valueB never gets logged

Link to code example: https://stackblitz.com/edit/react-hooks-demo-f69yc7?file=App.js

The current behavior

When clicked the "Test App" div valueB never gets logged.

The expected behavior

Not sure what the expected behavior should be, just it seemed strange valueB was never logged.

After putting some console.logs and using functional setState, I can see why valueB was not logged, because it was overwritten by setB(null) from previous renders useEffect return function. Just still this behavior seemed a bit strange to me, so wanted to share to make sure this is not a bug. Is it?

More details: https://stackoverflow.com/questions/68080085/state-update-being-overridden-by-another-previous-state-update

rickhanlonii wrote this answer on 2022-09-12

Yeah, that's the behavior in 16. If you check out the behavior in 18 below you can see that it's been updated to batch the updates with a more predictable outcome (automatic batching):

https://stackblitz.com/edit/react-hooks-demo-nd2wau?file=App.js

gmoniava wrote this answer on 2022-09-12

Yeah I had already checked that it worked in 18. It was somewhat strange behavior isn't it?

More Details About Repo
Owner Name facebook
Repo Name react
Full Name facebook/react
Language JavaScript
Created Date 2013-05-24
Updated Date 2022-09-27
Star Count 195296
Watcher Count 6655
Fork Count 40431
Issue Count 1113

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
BUG: unexpected failures when calling fs functions (e.g. writeFile) with empty options object 4 2021-04-10 2022-09-25
Endless loop when using error callback 4 2022-03-22 2022-07-02
Support for custom HTTP agents 0 2022-01-06 2022-09-16
Issue installing in RPI and SRT 1.4.4[Q] 4 2021-10-12 2022-09-13
Dependabot can't resolve your Elixir dependency files 0 2021-07-28 2022-09-13
No "retry" on practice failed due to insufficient material 3 2022-04-29 2022-08-27
Fails to run example on macOS 5 2021-09-25 2022-08-25
Please invite me to the GitHub Community Organization 2 2022-06-17 2022-07-21
Launcher crashing on login (FFXIV being launched correctly with Dalamud enabled) 1 2022-07-05 2022-09-16
onKernelController receives a FilterControllerEvent in older SF versions 2 2020-12-18 2021-12-19
HBOT is not showing accurrate data for status live and ticker live command for Kraken 1 2021-11-19 2021-12-11
Training failed in single GPU 4 2021-11-09 2022-09-16
Swiping Event 5 2018-09-30 2022-01-16
[UX] Consolidate the places where we list available updates... 4 2018-04-19 2022-08-22
Typo in Getting started section 1 2022-01-19 2022-09-26
Reading CONECT records in PDB files with >99999 Atoms. 9 2021-07-22 2022-07-08
Cannot find name $ref (use Ref Sugar (take 2)) 1 2021-10-20 2022-09-10
Activity Input property is null but designer shows a selected value when options are provided 7 2021-12-19 2022-07-21
Mobile view with wide content causes the navbar button to disappear to the right 0 2022-06-04 2022-09-23
[bug] 当列配置了fixed="left"后,拖拽无效 0 2022-08-22 2022-09-19
Get index of hit (i.e. position in list - 0, 1, 2, 3...) 2 2021-06-09 2022-09-15
Indicate folders / devices where the remote end is paused. 5 2022-04-29 2022-07-17
CI should use ocaml/ocaml#trunk 0 2022-01-18 2022-09-13
*Not an Issue, just looking for advice* Logging in on a Local host seems to resolve log in but client is still counted as logged out 2 2022-04-09 2022-08-21
jest test: TypeError: Cannot read properties of null (reading 'breakpoints') 1 2021-10-04 2022-09-27
useList not populating data from query 1 2021-09-28 2022-08-18
Does it have a GDM theme? 6 2019-02-15 2022-09-14
Running Nativescript App using 0.21.3 throws window is not defined 1 2021-09-06 2022-09-20
Feature Request: Circuit Breaker 2 2021-10-20 2022-09-21
Add table digitalocean_storage_spaces 2 2021-07-29 2022-07-21
Add table digitalocean_database_connection 2 2021-08-02 2022-07-24
Chia blocks misplaced/pool activity - went solo, yet block rewards (1.75) transferred to pool 8 2022-06-09 2022-09-25
switch master-slave? 1 2022-08-03 2022-09-09
[FEATURE] Storage tiering 3 2022-08-19 2022-09-01
`int_var =+ value` works when it shouldn't 3 2021-10-23 2022-08-30
Executing `PanelContainer.notification(11)` crashes Godot 3 2021-10-23 2022-09-02
Compiler Warning 0 2021-07-14 2022-01-13
Unable to install bcrypt using the latest pipenv (2021.11.23) 4 2021-12-09 2022-09-15
Android Basics: conditional-dice-roll-behavior 2 2022-02-21 2022-08-16
Upgrade Aptible CLI to 0.11.0 3 2017-06-29 2022-02-07
Laminar sometimes sends duplicated reliable messages 5 2019-10-26 2022-09-19
`Page Down`/`Page Up` Hide a Line of Code 5 2021-10-14 2022-08-30
ToLocalTime method mentioned in the documenation does not exists 4 2022-05-10 2022-09-12
build.gradle error while building project in android studio 7 2021-06-10 2022-09-22
The question of the observed outcome input for DynamicDML 0 2022-07-13 2022-09-18
use gauss function, but request with linear function 0 2022-05-05 2022-09-09
Lerna hoists packages to workspace root, making `pod install` fail to find necessary resources 1 2022-06-21 2022-09-10
EF Core has the same issue as my Linq provider wrt VB.NET build in ns libraries 3 2021-09-22 2022-01-29
[camera_web] Support camera image streams on the web 0 2021-10-26 2022-09-22
[camera] Support focus, zoom, exposure and flash controls on windows platform 1 2022-01-31 2022-09-07