fix(joint-react): useCells falls back to collection for non-graph cells#3349
Merged
kumilingus merged 1 commit intoJun 8, 2026
Conversation
`useCells(collection, …)` previously resolved every member id through the GraphProvider's cell container. Cells living outside the graph (e.g. `ui.Clipboard` clones, freshly constructed `dia.Cell` instances) were silently skipped, so a selector like `(cells) => cells.length === 0` always returned `true` regardless of how many cells the collection actually held. Resolve cells from the collection itself when the graph container lacks them. The raw `dia.Cell` is converted on the fly via the existing `toCellRecord` mapper, and a per-hook `WeakMap<dia.Cell, AnyCellRecord>` keeps the converted records reference-stable across renders so the outer shallow-equality short-circuit can still fire. Per-cell `change` events are not subscribed for the fallback path — the only caller today (clipboard membership) needs add/remove/reset reactivity, and the collection-level subscription already covers that. Adding per-cell listening is straightforward later if a use case appears. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
samuelgja
approved these changes
Jun 8, 2026
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.
Summary
useCells(collection, …)previously resolved every member id through the GraphProvider's cell container. Cells living outside the graph (e.g.ui.Clipboardclones, freshly constructeddia.Cellinstances) were silently skipped, so a selector like(cells) => cells.length === 0always returnedtrueregardless of how many cells the collection actually held.Resolve cells from the collection itself when the graph container lacks them. The raw
dia.Cellis converted on the fly via the existingtoCellRecordmapper. A per-hookWeakMap<dia.Cell, AnyCellRecord>keeps the converted records reference-stable across renders so the outer shallow-equality short-circuit can still fire.Per-cell
changeevents are not subscribed for the fallback path — the only caller today (clipboard membership) needs add/remove/reset reactivity, which the collection-level subscription already covers. Adding per-cell listening is straightforward later if a use case appears.Changes
packages/joint-react/src/hooks/use-cells.ts— newresolveCellhelper,pickCells/computeNextthreadcollection+WeakMapcache through; collection overload JSDoc updated.packages/joint-react/src/hooks/__tests__/use-cells.test.tsx— 3 new tests covering non-graph cells (records returned, length-selector reactive, ref stable across renders).Test plan
yarn jest --testPathPatterns=\"use-cells\"— 60 tests pass (incl. 3 new)yarn jestin@joint/react— cleanyarn typecheckin@joint/react-plus(downstream consumer of new behavior)🤖 Generated with Claude Code