Skip to content

fix: schedule re-render when setState is called before component mount - #77

Merged
bchelkowski merged 1 commit into
masterfrom
fix/kopytko-updater-pre-mount-state-update
Apr 8, 2026
Merged

bchelkowski merged 1 commit into
masterfrom
fix/kopytko-updater-pre-mount-state-update

Conversation

@bchelkowski

Copy link
Copy Markdown
Member

When a child component fires an observeFieldScoped callback synchronously during the parent's renderElement (e.g. a cache-hit result field is already set when the observation is registered), setState is called on the parent before setComponentMounted has run. enqueueStateUpdate correctly stored the partial state in _pendingPartialStates but returned early before scheduling a re-render timer, so the component never re-rendered after mount.

Fix: track whether there were any pending states in setComponentMounted and, if so, schedule a setTimeoutCore(0) re-render — matching the behaviour that enqueueStateUpdate would have produced had the component already been mounted.

Also adds two regression tests and expands the renderer.md documentation to describe the observeFieldScoped synchronous-callback platform behaviour that triggers this edge case.

When a child component fires an observeFieldScoped callback synchronously
during the parent's renderElement (e.g. a cache-hit result field is already
set when the observation is registered), setState is called on the parent
before setComponentMounted has run. enqueueStateUpdate correctly stored the
partial state in _pendingPartialStates but returned early before scheduling
a re-render timer, so the component never re-rendered after mount.

Fix: track whether there were any pending states in setComponentMounted and,
if so, schedule a setTimeoutCore(0) re-render — matching the behaviour that
enqueueStateUpdate would have produced had the component already been mounted.

Also adds two regression tests and expands the renderer.md documentation to
describe the observeFieldScoped synchronous-callback platform behaviour that
triggers this edge case.
@bchelkowski
bchelkowski requested a review from a team as a code owner April 8, 2026 10:28
@bchelkowski
bchelkowski requested review from praveenKumarCH534 and tbazelczuk and removed request for a team April 8, 2026 10:28
@bchelkowski
bchelkowski merged commit 6aa25ee into master Apr 8, 2026
1 check passed
@bchelkowski
bchelkowski deleted the fix/kopytko-updater-pre-mount-state-update branch April 8, 2026 10:50
github-actions Bot pushed a commit that referenced this pull request Apr 8, 2026
## [3.4.1](v3.4.0...v3.4.1) (2026-04-08)

### Bug Fixes

* schedule re-render when setState is called before component mount ([#77](#77)) ([6aa25ee](6aa25ee))
@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 3.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant