Skip to content

Only remount parent-passed components when their identity changed#3881

Open
T4rk1n wants to merge 1 commit into
devfrom
fix/remounts
Open

Only remount parent-passed components when their identity changed#3881
T4rk1n wants to merge 1 commit into
devfrom
fix/remounts

Conversation

@T4rk1n

@T4rk1n T4rk1n commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Since #3570, every component passed down from a parent whose children were updated by a callback got a bumped render key, forcing React to unmount and remount the entire subtree on every callback run - even when the returned children were the same components with only new prop values. This reset descendant state and made large subtree updates 3-4x slower (#3846).

The forced remount is now conditional: the render key is only bumped when the component identity (namespace, type, id) at that path actually changed. The same component reconciles in place as before 4.2.0, while a different component at the same path still remounts, and stale descendant layout hashes are still reset - keeping #3330 fixed.

The one reverted semantic from #3570 is that returning the same component (same type and id) from a callback no longer resets its internal state; return it with a different id to force a remount.

Fixes #3846

Since #3570, every component passed down from a parent whose children
were updated by a callback got a bumped render key, forcing React to
unmount and remount the entire subtree on every callback run - even
when the returned children were the same components with only new prop
values. This reset descendant state and made large subtree updates 3-4x
slower (#3846).

The forced remount is now conditional: the render key is only bumped
when the component identity (namespace, type, id) at that path actually
changed. The same component reconciles in place as before 4.2.0, while
a different component at the same path still remounts, and stale
descendant layout hashes are still reset - keeping #3330 fixed.

The one reverted semantic from #3570 is that returning the same
component (same type and id) from a callback no longer resets its
internal state; return it with a different id to force a remount.

Fixes #3846

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@BSd3v

BSd3v commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@T4rk1n

I believe that this resets to the initial behaviour of 4.2.0, this may be better served with a dash update type? For example, if the dev wants to reset the component via a callback, they just tell the callback to do so, which this forces its way down the tree? The default could be to not force remount.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 4.2.0: callback-rendered children unmount/remount instead of updating in place (regression, bisects to #3570)

2 participants