Skip to content

Release unmounted reflex_xy chart views after React clears DOM refs - #554

Merged
FarhanAliRaza merged 3 commits into
mainfrom
farhan/issue-548-reflex-unmount-views
Nov 4, 2026
Merged

FarhanAliRaza merged 3 commits into
mainfrom
farhan/issue-548-reflex-unmount-views

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #548.

Root cause

XYChart.jsx registered each view in window.__xy_views under outerRef.current?.id || mid, then re-read that expression during effect cleanup. React detaches DOM refs (object refs nulled, callback refs called with null) before passive effect cleanup, so cleanup fell back to the mount id and the delete missed the id-keyed entry. Destroyed views (e.g. the showcase board after the small-multiples toggle) stayed in the registry.

Fix

  • Capture the registry key once per mount when the effect runs, and reuse it for both registration and removal (live and static modes).
  • New releaseViewKey(key, view) deletes the entry only while it still holds this mount's view, so a later mount reusing the same id is never evicted by an earlier mount's cleanup.

Tests

  • tests/reflex_socket_connection.cjs (run via tests/test_reflex_socket_connection.py): the stub now detaches object and callback refs before running cleanup, matching React's order. All five connection-order variants assert exact registry keys and an empty registry after the last unmount. New test covers anonymous + named mounts releasing their views while the shared app transport stays connected. Before the fix, six tests failed; after it, all seven pass.
  • scripts/reflex_ws_smoke.py: the cond/foreach step now asserts exact counts 13 → 15 → 13 across the toggle and back, that board leaves the registry, and that no registered view is destroyed. Verified it times out on the old JSX and passes with the fix against the running demo (prod, single port).
  • tests/reflex_adapter + socket gate: 252 passed. pre-commit, ruff check, ruff format --check clean.

Not covered: client-side navigation to /kinds and back — the smoke loads /kinds with a full page navigation.

Docs

  • spec/design/reflex-integration.md: new "Unmount releases the view" paragraph.
  • news/548.bugfix.md.

Generated by Claude Code

View guided diff Turn on auto-fix

…548)

XYChart.jsx re-read outerRef.current?.id during effect cleanup to find its
window.__xy_views key. React nulls DOM refs before passive effect cleanup,
so cleanup fell back to the mount id and left the destroyed, id-keyed view
registered (e.g. the showcase board after the small-multiples toggle).

Capture the registry key once per mount and reuse it for registration and
removal, deleting the entry only while it still holds this mount's view.

The Socket.IO connection-order gate now detaches object and callback refs
before cleanup, matching React, and asserts the registry empties for named
and anonymous mounts. The browser smoke asserts exact 13 -> 15 -> 13 view
counts across the cond toggle, with the board released.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2df73742-9740-4ebf-a29d-246dbb233174
Commits

Reviewing files that changed from the base of the PR and between 5e58b12 and f8b34db.

Files selected for processing: 5
  • news/548.bugfix.md
  • python/reflex_xy/assets/XYChart.jsx
  • scripts/reflex_ws_smoke.py
  • spec/design/reflex-integration.md
  • tests/reflex_socket_connection.cjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

The PR removes unmounted chart views using a saved registry key without deleting a newer view under the same key.

  • Unmounted charts now leave the view registry without removing newer mounts.

Reviews (3) · Last reviewed commit: "Bound the smoke's registry settle wait; ..." · Reviewed by Greptile

Comment thread tests/reflex_socket_connection.cjs Resolved
@codspeed

codspeed Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 14 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 109 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing farhan/issue-548-reflex-unmount-views (f8b34db) with main (ae06191)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/reflex_ws_smoke.py Resolved
Comment thread tests/reflex_socket_connection.cjs Resolved
Comment thread python/reflex_xy/assets/XYChart.jsx Resolved
- Socket gate: static src mounts (named and anonymous) release their views
  after refs detach, and an older mount's cleanup leaves a newer view under
  the same key registered. Both fail against an unconditional delete or a
  ref re-read at cleanup.
- Browser smoke: wait for the view registry to settle before reading the
  baseline used by the exact cond-toggle counts.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/reflex_ws_smoke.py Resolved
Comment thread spec/design/reflex-integration.md Resolved
Comment thread scripts/reflex_ws_smoke.py Resolved
- Settle the view registry with one in-page poll (1.5 s quiet, 30 s limit)
  so a stalled page cannot extend the wait past its budget; name the
  durations in comments.
- Spec: the transport-stays-connected claim applies to live mounts; static
  src mounts never open the data plane.
@FarhanAliRaza
FarhanAliRaza merged commit 3a67d08 into main Nov 4, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reflex_xy: unmounted charts retain destroyed views after React clears DOM refs

1 participant