Skip to content

[Fiber] Double invoke Effects in StrictMode after Fast Refresh#659

Open
everettbu wants to merge 2 commits into
mainfrom
sebbie/se-fr
Open

[Fiber] Double invoke Effects in StrictMode after Fast Refresh#659
everettbu wants to merge 2 commits into
mainfrom
sebbie/se-fr

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35962
Original author: eps1lon


Summary

Fixes react/react#29915

Ensures Effects are also double invoked when a Component newly mounts due to Fast Refresh. Looks to have been an oversight in the remountFiber path.

How did you test this change?

  • Added test (see first commit for previous behavior)

@everettbu everettbu added CLA Signed React Core Team Opened by a member of the React Core Team labels Mar 5, 2026
@greptile-apps

greptile-apps Bot commented Mar 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes an oversight where the remountFiber path (used during Fast Refresh) did not set the PlacementDEV flag on newly created fibers. Without this flag, StrictMode's double-invocation of effects was skipped for components remounted via Fast Refresh, contrary to the behavior for all other newly mounted components.

  • Adds PlacementDEV flag in remountFiber to match the existing pattern in ReactChildFiber.js
  • Adds two tests covering double invocation of effects during Fast Refresh in StrictMode (existing effect and newly added effect)
  • Change is entirely within a __DEV__ guard, so there is zero production impact

Confidence Score: 5/5

  • This PR is safe to merge — it's a minimal, well-scoped DEV-only bug fix with test coverage.
  • The code change is a single-line addition of a flag that already exists in all analogous code paths. The remountFiber function is entirely gated by __DEV__, so there is no production risk. Two comprehensive tests validate the expected behavior. The fix aligns with the established pattern in ReactChildFiber.js.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/react-reconciler/src/ReactFiberBeginWork.js Adds PlacementDEV flag alongside Placement in remountFiber, matching the pattern already used in ReactChildFiber.js. This ensures newly mounted fibers via Fast Refresh are recognized for StrictMode double-invocation of effects. The function is gated by __DEV__, so there is no production impact.
packages/react-refresh/src/tests/ReactFresh-test.js Adds two new test cases verifying that effects are double-invoked in StrictMode after a Fast Refresh remount: one where the effect existed before the refresh, and one where the effect is newly added during the refresh. Tests follow existing patterns and use proper act/patch helpers.

Last reviewed commit: 71c0f2a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[React 19] useEffect does not re-fire on hot reload with React 19 and vite

2 participants