fix(memory-graph): keep node selection when pagination changes the node count#1263
fix(memory-graph): keep node selection when pagination changes the node count#1263abhay-codes07 wants to merge 1 commit into
Conversation
…ount The slideshow effect depends on nodes.length and its inactive branch unconditionally cleared the selected node. With the slideshow off (the default), any change in node count re-ran the effect and wiped the user's selection: pin a node's popover, zoom out far enough for the load-more trigger to append a page of documents, and the popover vanishes mid-read. The reset also fired a stray coolDown() on the simulation. Track the previous slideshow state in a ref and only clear the selection on a real active -> inactive transition.
|
I don't think this issue exists in prod, I checked and could not reproduce this closing this for now, if you find this issue in prod, feel free to tag me |
|
@ishaanxgupta thanks for checking. Taking you up on the "tag me" offer, because I think this reproduces on the default path rather than through the slideshow. The trigger is not the slideshow being on, it is the effect re-running while the slideshow is off. On current useEffect(() => {
if (!isSlideshowActive || nodes.length === 0) {
if (!isSlideshowActive) {
setSelectedNode(null) // clears selection on *every* re-run
simulationRef.current?.coolDown()
}
return
}
// ...
}, [isSlideshowActive, nodes.length]) // re-runs whenever nodes.length changes
Repro without the slideshow:
It is easy to miss because it only bites when there is a pinned selection and the node count changes in the same session, so a quick click-test without pagination looks fine. The PR keeps the active → inactive transition behaving exactly as before and only stops the no-op re-runs from clearing the selection. If that repro holds up on your end, would you mind reopening? Happy to rebase onto the latest |
What
Pin a node's popover in the memory graph, zoom out far enough for the load-more trigger to fetch the next page, and the popover vanishes mid-read.
The slideshow effect in
memory-graph.tsxdepends onnodes.length, and its inactive branch unconditionally cleared the selected node:With the slideshow off (the default for every consumer), any change in node count re-ran the effect and wiped the user's selection — pagination appending documents being the common trigger. It also fired a stray
coolDown()on the simulation each time.Fix
Track the previous slideshow state in a ref and only clear the selection on a genuine active → inactive transition. Re-runs caused by
nodes.lengthchanging while the slideshow was never active are now no-ops.Testing
bun run testinpackages/memory-graph— 188 passbun run check-types— cleanBehaviour notes for review: the active → inactive transition still clears the selection and cools the simulation exactly as before; the only change is that re-runs where the slideshow was never active no longer touch the selection.