Repository navigation
Conversation
…ections updateConnections reduced into the existing Map and assigned the same reference back to $connectionsMap, so the signal did not notify and $connections stayed stale. Connections added via graph.updateEntities were not rendered and were missing from getConnections()/toJSON(). Mutate the live map sequentially (keeps duplicate-id behavior: last entry wins, state reused) and publish a new Map reference via notifyConnectionMapChanged(). Empty input is a no-op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideFixes stale reactive connection data by updating the live map sequentially and publishing a new Map reference once for each non-empty update batch. The accompanying tests cover subscriber notification, serialized/computed results, rendering, duplicate-ID semantics, state identity, and empty-input behavior. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
|
Preview is ready. |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/graph/src/store/connection/ConnectionList.ts" line_range="171-175" />
<code_context>
+ if (!connections.length) return;
+ // Mutate sequentially so getOrCreateConnection sees earlier entries of this batch (duplicate ids),
+ // then publish a new Map reference: reassigning the same Map would not notify subscribers.
+ connections.forEach((connection) => {
const c = this.getOrCreateConnection(connection);
- acc.set(c.id, c);
- return acc;
- }, this.$connectionsMap.value);
+ this.$connectionsMap.value.set(c.id, c);
+ });
+ this.notifyConnectionMapChanged();
}
</code_context>
<issue_to_address>
**Partial batches stay invisible**
When a batch contains a valid connection followed by an invalid value that throws during processing, an earlier connection is inserted into the live map, but a later `getOrCreateConnection` throws before `notifyConnectionMapChanged()` runs. The map then contains the earlier connection while `$connections` and its subscribers remain stale.
Publish the map in a `finally` block so any mutations completed before an exception are visible to subscribers.
</issue_to_address>
### Comment 2
<location path="packages/graph/src/store/connection/ConnectionList.ts" line_range="168-175" />
<code_context>
- public updateConnections(connections: TConnection[]) {
- this.$connectionsMap.value = connections.reduce((acc, connection) => {
+ public updateConnections(connections: TConnection[]): void {
+ if (!connections.length) return;
+ // Mutate sequentially so getOrCreateConnection sees earlier entries of this batch (duplicate ids),
+ // then publish a new Map reference: reassigning the same Map would not notify subscribers.
+ connections.forEach((connection) => {
const c = this.getOrCreateConnection(connection);
- acc.set(c.id, c);
- return acc;
- }, this.$connectionsMap.value);
+ this.$connectionsMap.value.set(c.id, c);
+ });
+ this.notifyConnectionMapChanged();
}
</code_context>
<issue_to_address>
**Sparse batches spuriously notify**
When `updateConnections` receives an array with a positive length but only holes, `forEach` skips holes, so a nonzero-length sparse array processes no connections but still calls `notifyConnectionMapChanged()`. Subscribers receive a change notification and `BlockConnections` schedules an unnecessary render despite no data changing.
Notify only if the iteration processed at least one connection.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: packages/graph/src/store/connection/ConnectionList.ts:175
…op notify Notify in a finally block so entries applied before a throwing entry (e.g. untyped null input) are published to $connections subscribers, and notify only when at least one entry was applied, so empty and sparse arrays do not trigger a spurious change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
ConnectionsStore.updateConnectionsreduced into the existingMapand assigned the same reference back to$connectionsMap. The signal saw no change, so it did not notify, and the computed$connectionsstayed stale.Effect for
graph.updateEntities({ connections: [newConnection] }):getConnectionState(id)found the new connection;$connections,getConnections()andtoJSON()did not include it;BlockConnectionssubscribe to$connections, so noBlockConnectionwas mounted and nothing was rendered.A later
addConnection(which callsnotifyConnectionMapChanged()) hid the problem.Fix
packages/graph/src/store/connection/ConnectionList.ts:notifyConnectionMapChanged()to publish a newMapreference (the same patternaddConnection/deleteConnectionsuse);getOrCreateConnectionstill sees earlier entries of the same batch, so duplicate ids behave as before: oneConnectionState, reused and updated, last entry wins;: voidreturn type.Behavior note: a batch that only updates existing ids now also publishes a new
$connectionsarray (before, nothing fired). The result is one extra keyed children diff inBlockConnections; component and state identity are kept.Tests
New
packages/graph/src/store/connection/updateConnections.test.ts:updateEntitiesnotifies$connectionsonce and appears in$connections/getConnections()/toJSON();BlockConnectionfor it;updateConnectioncalled once), one notification;Without the fix, 4 of 5 tests fail; the empty-input test guards the new early return.
Checks
pnpm run typecheckpnpm run test:type-configspnpm test: graph 334 passed / 6 todo, graph-react 141 passed / 4 skipped, devtools 11 passedpnpm run lint: 0 errors (1 pre-existing storybook warning)node scripts/strict-diagnostics.mjs🤖 Generated with Claude Code
Summary by Sourcery
Publish connection map updates reliably so connections added through entity updates appear in state, serialization, and the rendered graph.
Bug Fixes:
Enhancements:
Tests: