Skip to content

fix: preserve reactive UI updates for app.clone().embed() - #12288

Open
hai-dep-try wants to merge 1 commit into
marimo-team:mainfrom
hai-dep-try:fix/app-clone-embed-4249
Open

hai-dep-try wants to merge 1 commit into
marimo-team:mainfrom
hai-dep-try:fix/app-clone-embed-4249

Conversation

@hai-dep-try

Copy link
Copy Markdown

📝 Summary

Closes #4249

Fixes reactive UI updates when embedding a cloned app directly via await app.clone().embed() (without assigning the clone to a separate cell's global variable).

Root cause

  1. Kernel.set_ui_element_value previously only discovered parent cells to re-run by scanning self.globals for references to child_context.app._app. Because app.clone() returned an unbound temporary App object, no parent cell was scheduled and set_ui_element_value returned False.
  2. Even if the parent cell re-ran, executing app.clone() again inside the cell created a brand new App and AppKernelRunner, discarding the child's updated UI state.

Changes

  • marimo/_runtime/context/types.py: Track clone_seq per ExecutionContext cell run.
  • marimo/_ast/app.py:
    • Record parent embed caller cell IDs in AppKernelRunnerRegistry during App.embed().
    • Reuse cloned App instances across reactive re-runs of the same cell keyed by (id(ctx), cell_id, source_app, clone_seq) in App.clone(), and clean up tracked state on remove_runner / shutdown.
  • marimo/_runtime/runtime.py:
    • Include registered embed caller cells (still present in self.graph.cells) in referring_cells inside Kernel.set_ui_element_value.
    • Invalidate cached cell clones on explicit Kernel.run / Kernel.delete_cell so manual cell re-execution creates fresh clones.
  • tests/_ast/test_app.py: Add regression tests covering app.clone().embed() reactive UI updates, multiple independent clones in one cell, and reset on explicit cell re-execution.

Verification

  • ruff check marimo/_ast/app.py marimo/_runtime/context/types.py marimo/_runtime/runtime.py -> All checks passed!
  • ruff format --check marimo/_ast/app.py marimo/_runtime/context/types.py marimo/_runtime/runtime.py tests/_ast/test_app.py -> 4 files already formatted
  • pytest tests/_ast/test_app.py tests/_runtime/test_context.py -v -> 111 passed, 3 skipped (3 matplotlib-optional tests skipped in local venv).

👋 First time contributor introduction

Hi! I'm a Python developer contributing a fix for reactive embedded cloned apps (#4249). Looking forward to your feedback!

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes.

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

Track parent caller cells in AppKernelRunnerRegistry and reuse cloned App instances across reactive cell re-runs while resetting them on explicit cell execution or deletion.

Fixes marimo-team#4249.

Signed-off-by: hai-dep-try <duchain18@gmail.com>
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@hai-dep-try

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

This branch has not been deployed

No deployments
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.

Cloning a module issue

1 participant