reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Cached var are not busted on hot reload

Open Lendemor opened this issue 1 year ago β€’ 1 comments

Describe the bug Cached var are not busted when you change some values inside the var (only when there is no dependency that could trigger the cachebust)

To Reproduce Steps to reproduce the behavior:

  1. Run the snippet
import reflex as rx

class MyState(rx.State):
    @rx.var(cache=True)
    def main_data(self) -> list[dict]:
        return [
            {"id": "2"},
            {"id": "3"},
        ]

@rx.page(route="/mypage", title="My Page")
def mypage() -> rx.Component:
    return rx.vstack(
        rx.foreach(MyState.main_data, main_data_component),
        spacing="0",
    )
  1. Remove one of the two entry in the list in main_data
  2. Wait for reload
  3. The page still display the initial cached value (2 items) instead of the new one (1 item)

Expected behavior Cached var value should be busted on hot-reload.

Lendemor avatar Sep 24 '24 20:09 Lendemor

Had the same issue, they could no reproduce it. Issues was closed.

A workaround is creating a new project and migrating the files...

ikuV avatar Sep 26 '24 11:09 ikuV

Any update shere?

ikuV avatar Oct 15 '24 08:10 ikuV

0.6.3 the same. When the List of the table changes, the front end of the total amount of data cannot change at the same time. The front end will display the correct information after refreshing.

class ProductsTable(rx.State):
    p_total_times: int = 0

    @rx.var(cache=True)
    def get_product_data(self) -> list[FolderType]:
        ...
        self.p_total_items = len(reset_files)
        ...
        return product_data

# table.py
rx.text(f"Total {ProductsTable.p_total_items}", variant="soft")`

wenwen6183 avatar Oct 20 '24 02:10 wenwen6183

Known workarounds for this issue:

  • Interrupt the app with Ctrl+C and run reflex run again. On the first run, the state data saved on disk will be removed. or
  • Add state_manager_mode="memory" to rxconfig.py. In this mode, hot reload will reset the full state to the default value defined in your code.

Lendemor avatar Oct 21 '24 19:10 Lendemor