fix(joint-react): tolerate a cell removed mid-render (useCell) and assign the forwarded ref during commit (useCombinedRef) - #3447
Open
samuelgja wants to merge 1 commit into
Conversation
…ensure correct behavior during controlled updates
This was referenced Aug 12, 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.
Description
Two independent React-hook lifecycle fixes in
@joint/react, each with a jest repro. Both are reachable through ordinary, documented usage and both are masked by StrictMode's effect remount, so they only surfaced in production builds.1.
useCell— tolerate a cell removed mid-render (fixes #3442)useCell()threwuseCell(): no cell with id "X"and took the whole paper down when a subscribed cell was removed from a controlledcellsarray (renaming a node id is a remove + add). ArenderElementsubtree that subscribes to its own cell — directly, or viauseMeasureElement->useCell(selectElementSize)for any content-sized node, i.e. the defaultHTMLBox/SVGTextrenderers — re-runs its selector against the already-removed cell before<Paper>reconciles the removal, because the controlled apply fires that cell's per-id listener synchronously in a layout effect.The wrapper selector now keeps the last value it resolved for the current id (one in-place-mutated ref, no per-render allocation) and returns it during that removed-mid-render window: the doomed subtree renders once more with stale data (equal to the cached value, so it does not even re-render) and unmounts on the next commit, instead of throwing. A cell that never resolved (genuine bad-id misuse / outside a render context) still throws.
Repro:
use-cell-controlled-removal.test.tsx— a realPaper+ subscribingrenderElementdoing a controlledb -> crename crashes to 0 elements before the fix, survives (2 elements, no error) after.2.
useCombinedRef— assign the forwarded ref during commit, not in a passive effect (fixes #3444)useCombinedRefassigned the forwarded ref inside a passiveuseEffect, one phase too late. React attaches refs during commit, before layout effects; a parent that reads the forwarded ref in its ownuseLayoutEffectsawnull.useMeasureElementis exactly that consumer — it readsnodeRef.currentin a layout effect, bails on null, and its dependency list does not change when the node is finally assigned, so a measured element stayed 0x0 in production.The hook now returns a proxy whose setter forwards during commit (
setForwardRefruns when React writes.current), keeping theRefObject.currentread interface consumers depend on — which a plain callback ref could not.Repro:
use-combined-ref-timing.test.tsx(rendered withreactStrictMode: false) — a parent layout effect seesnullbefore the fix, the node after.Motivation and Context
The
useCellcrash came out of a Mermaid-to-JointJS renderer where every keystroke in a node id took the canvas down; theuseCombinedRefone from an app measuringSVGTextdirectly — correct undervite dev, every node a bare label with no shape or layout once built for production. StrictMode (on for every story and test) masks both, which is why the suite was blind to them.Fixes #3442
Fixes #3444
🤖 Generated with Claude Code
https://claude.ai/code/session_01F3YAR6SSWn39wTNhBTyFGX