Skip to content

Add an explicit root lifecycle seam for backends - #13

Merged
yogthos merged 2 commits into
mainfrom
lifecycle-seam
Oct 17, 2026
Merged

yogthos merged 2 commits into
mainfrom
lifecycle-seam

Conversation

@isaksky

@isaksky isaksky commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #12; review the second commit only.

A backend that owns native resources, such as Qt, needs to unmount the root on its UI thread before destroying the container, and to drop the root's subscriptions when the native side has already gone. The :run contract offers neither: the only handle on the mounted root was whatever the mount-root! callback happened to return.

  • :run-lifecycle (fn [opts lifecycle]) is an optional backend op that receives :mount!, :unmount! and :abandon! thunks and owns the root's lifetime. Backends implementing :run are unaffected; run falls back to it.
  • :dispose! lets the core hand back a widget it created but could not attach.
  • glimmer.core/abandon! detaches a mounted root's subscriptions without native calls, for roots a backend mounts itself with mount.
  • run now detaches the root's subscriptions when it returns, including for legacy :run backends. Previously the old tree stayed subscribed to defonce cells after the app quit.
  • A later run replaces the live root, as before, but only once its own root has mounted. A run the backend rejects before that, as Qt does for a second session, leaves the live run's reload! target in place.
  • A reload whose new root throws while mounting keeps the run's window and previous root fn, so a later reload! fills the window instead of finding nothing to reload. A reload queued before a run exits cannot touch a later run.

The README gains the two ops in the backend map and a Lifecycle paragraph. Tests are in test/glimmer/lifecycle_test.clj, including the exceptional exits the seam exists for: a legacy loop that throws still has its root detached and the live root released, and abandon! detaches a run's subscriptions at once without a native call, through a re-render queued before it and run's finalizer alike, leaving unmount!, abandon! and reload! as no-ops. The Qt backend in glimmer-qt is the first consumer of the seam.

🤖 Generated with Claude Code

@isaksky
isaksky force-pushed the reconciler-subscriptions branch from c7078b7 to 3b0272a Compare October 16, 2026 01:25
@isaksky
isaksky marked this pull request as draft October 16, 2026 01:39
@yogthos

yogthos commented Oct 16, 2026

Copy link
Copy Markdown
Member

yeah that's a reasonable addition as well

@isaksky
isaksky force-pushed the reconciler-subscriptions branch from 3b0272a to 886e193 Compare October 16, 2026 03:28
A backend that owns native resources can implement :run-lifecycle and receive
:mount!, :unmount! and :abandon! callbacks, instead of relying on the value
the mount-root! callback happens to return. :dispose! lets the core hand back
a widget it created but could not attach, and glimmer.core/abandon! detaches
a mounted root's subscriptions without native calls, for roots a backend mounts
itself when the native side is already gone.

run now detaches the root's subscriptions when it returns, including for
legacy :run backends, and a reload queued before a run exits cannot touch a
later run. A later run replaces the live root, as before, but only once its
own root has mounted, so a run the backend rejects before that (Qt refuses a
second session) leaves the live run's reload! target in place; and a reload
whose new root throws while mounting keeps the run's window and previous root
fn, so a later reload! fills the window instead of finding nothing to reload.
The lifecycle tests also cover the exceptional exits the seam exists for: a
legacy loop that throws still has its root detached and live-root released,
and abandon! detaches a run's subscriptions at once without a native call,
through a re-render queued before it and run's finalizer alike, leaving
unmount!, abandon! and reload! as no-ops.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@isaksky

isaksky commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Ready to be looked at.

@yogthos
yogthos changed the base branch from reconciler-subscriptions to main October 17, 2026 02:41
glimmer-appkit keeps the value its :run backend gets from mount-root! and reads
:inst off it for root-inst; returning nil broke that.
@yogthos
yogthos merged commit dc6f499 into main Oct 17, 2026
2 checks passed
@yogthos
yogthos deleted the lifecycle-seam branch October 17, 2026 02:44
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.

2 participants