Skip to content

Local rx._x.client_state setter raises ReferenceError when the setter is on a sibling component #7426

Closed

Description

@FarhanAliRaza

Summary

A local client state (rx._x.client_state(..., global_ref=False)) does not work when the setter is on a sibling component. A click raises a ReferenceError, and the reader keeps its default value.

Repro

import reflex as rx

local = rx._x.client_state(default="local-initial", global_ref=False)


class S(rx.State):
    pass


def index():
    return rx.vstack(
        rx.button("local set", on_click=local.set_value("local-clicked"), id="local-set"),
        rx.text(local.value, id="local-reader"),
    )


app = rx.App()
app.add_page(index)

Run the app and click "local set".

Expected

#local-reader shows local-clicked.

Actual

#local-reader keeps local-initial. The browser reports:

Uncaught ReferenceError: setIcgswkgu is not defined

Cause

The memoize plugin compiles the button into its own memo component. Its onClick calls the bare setter name (setIcgswkgu(...)). The useState hook that defines the setter is only in the page component, where the reader is. So the setter is not in scope in the button's component.

ClientStateVar.set_value does not attach the hooks to a local setter on purpose. A private copy of the state would update a value that no reader sees. So a local setter only works in the same component scope as its useState. Memoization splits sibling components into separate scopes, so this case does not work.

The bug occurs on main (7970e91f0). It is not related to #7407.

Activity

  1. linear-code commented on Oct 5, 2026

    @linear-code
  2. FarhanAliRaza commented on Nov 4, 2026

    @FarhanAliRaza
    ContributorAuthor

    Fixed on main by #6936. Each memoized component now calls its own useClientState hook, and the page scope maps them to one store entry. The setter is in scope where the click calls it, and the reader updates.

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