fix(bindx): notify global subscribers on nested child field edit (#51)#52
Merged
Merged
Conversation
A scalar field edit on a child entity (one registered as a child via registerParentChild — i.e. nested in a hasMany/hasOne) notified the entity-scoped subscribers but never the global subscribers. As a result usePersist().isDirty, which subscribes via store.subscribe() (global), stayed stale and a Save button gated on isDirty remained disabled after editing a nested field, even though getAllDirtyEntities() reported the change correctly. Root cause: notifyEntitySubscribers gated the global notification on notifiedKeys.size === 1, but that guard ran AFTER the parent-propagation loop had already grown the shared notifiedKeys set. For any leaf with a parent the size was >= 2 by then, so globals were never notified; a parentless entity had no recursion, so size === 1 held — which is why only nested entities were affected. Fix: capture isRoot (notifiedKeys.size === 0) before adding/recursing and gate the global notification on isRoot. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PbKRVbhqE2N3uTi9mbaWb6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #51.
Problem
A scalar field edit on a child entity (registered via
registerParentChild— i.e. nested in ahasMany/hasOne) notified the entity-scoped subscribers but never the global subscribers.usePersist().isDirtysubscribes throughstore.subscribe()(global), so a Save button gated onisDirtystayed disabled after editing a nested field — even thoughgetAllDirtyEntities()reported the change correctly. A top-level (parentless) entity edit was unaffected.Root cause
SubscriptionManager.notifyEntitySubscribersgated the global notification onnotifiedKeys.size === 1, but that guard ran after the parent-propagation loop had already grown the sharednotifiedKeysset. For any leaf with a parent,size >= 2by the time the guard ran → globals skipped. A parentless entity has no recursion, sosize === 1held — which is why only nested entities were affected.Fix
Capture
isRoot = notifiedKeys.size === 0before adding the key / recursing, and gate the global notification onisRoot.Test
Ports the regression test from the issue to
tests/unit/store/global-subscriber-child-field-edit.test.ts:Full
tests/unit/store/suite +subscriptionRekeypass (143 tests). The pre-existingbindx-formFormHasManyRelationScopefailure and theexample/App.tsxtypecheck error are unrelated and present onmain.🤖 Generated with Claude Code