reactjs / reactjs/react.dev

Timing of effects

Open
#1,598 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

Although useEffect is deferred until after the browser has painted, it's guaranteed to fire before any new renders. React will always flush a previous render's effects before starting a new update.

Is this true in both concurrent and non-concurrent mode. It would appear intuitively that these two call-sites in non-concurrent mode would be deterministic:

ReactDOM.render(<Foo>, container)
ReactDOM.render(<Foo>, container)

That is it would invoke a new render before the effect in the first render has been invoked.

If so would it make more sense to specify it is only in relation to effects i.e previous effects are guaranteed to run before future effects.

As it stands, it looks appears as though the "render" call-site is non-deterministic in non-concurrent.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the quoted documentation statement about effects being flushed before new renders, then compare its wording with the two ReactDOM.render call sites and both concurrent and non-concurrent behavior. Done means the documentation clearly states the supported guarantee and resolves whether it applies to renders generally or only to effect ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.