Skip to content

Compose host: rememberSaveable for Python (remember_saveable), and saved state survives recreation #174

Closed

Description

@b-re-w

User decision (2026-10-04): remember_saveable must be supported, as in the original pycomposeui (app-template pycomposeui Runtime.android.kt rememberSaveableWrapper) that UI.ipynb ran against. pythonx-compose wraps it (getValue/setValue/.value); this repository supplies the Kotlin side.

Work:

  • A Kotlin @composable wrapper in python-multiplatform-compose that dispatches on the initial value's type (Int, Long beyond 32 bits, Boolean, Double, String) to rememberSaveable { mutableXStateOf(init) } and returns the MutableState, exposed through the binder (KSP table). Called outside a composition it fails, as in Kotlin.
  • PythonAppView/PythonWidget compose under the platform's SaveableStateRegistry (Android: the Activity's; desktop: whatever the host provides), so saved values survive recreation.
  • Test: desktop, a host scene with a SaveableStateRegistry; a Python root remembers values of each type, changes them, the registry is saved, the composition is torn down and recreated from the saved state, and the values come back. Red first.
  • Notebook E2E: switch the root and state cells to the notebook's own spelling once pythonx-compose ships its wrapper (main.App.messages, getValue/setValue).
    Completion: the test above, compose fixture and notebook E2E green; SPEC entry.

Activity

  1. b-re-w commented on Oct 3, 2026

    @b-re-w
    MemberAuthor

    Landed in develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions