Skip to content

Lint rule: warn when mo.state() is created in a cell with reactive inputs #11093

Description

@alphaleporus

Description

While building marimo dashboards for gprMax (merged in gprMax/gprMax#810), I hit a silent data-loss bug: a list accumulated in mo.state reset to its initial value whenever an unrelated dropdown changed.

The cause was that mo.state([]) lived in a cell that also read the dropdown. Each rerun of that cell calls mo.state() again and gets a fresh State, so the old value is dropped and dependents rerun with []. This matches the implementation, so I don't think it's a runtime bug. But neither the docstring nor the state guide mentions it, and nothing errors or warns. The data just disappears.

Repro (marimo 0.25.1):

import marimo as mo
choice = mo.ui.dropdown(["a", "b"], value="a")
choice
choice.value  # any reactive input
get_items, set_items = mo.state([])
add = mo.ui.button(label="Add", on_click=lambda _: set_items(lambda v: v + [len(v)]))
add
get_items()

Click Add three times to get [0, 1, 2]. Change the dropdown and the list resets to []. Moving mo.state([]) into its own cell with no reactive inputs fixes it.

Proposal:

  1. A marimo check rule that flags mo.state() in a cell whose references include anything beyond imports.
  2. A short note in the state guide that state lives only as long as the cell that created it.

Are you willing to submit a PR? (You must receive approval from the team before submitting a PR.)

  • Yes

Alternatives

Documenting the behavior only, without a lint rule. Cheaper, but the failure is silent, so people are unlikely to find the docs note until after they have lost data.

Additional context

Before fix, dropdown "a": 3 items
Image
Before fix, dropdown "b": reset to 0 items
Image

After fix, dropdown "a": 3 items
Image
After fix, dropdown "b": still 3 items
Image

Activity

  1. akshayka commented on Oct 5, 2026

    @akshayka
    Contributor

    Thanks for the issue. We'd welcome a PR

  2. self-assigned this
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions