Cached var are not busted on hot reload
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:
- 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",
)
- Remove one of the two entry in the list in
main_data - Wait for reload
- 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.
Had the same issue, they could no reproduce it. Issues was closed.
A workaround is creating a new project and migrating the files...
Any update shere?
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")`
Known workarounds for this issue:
- Interrupt the app with
Ctrl+Cand runreflex runagain. On the first run, the state data saved on disk will be removed. or - Add
state_manager_mode="memory"torxconfig.py. In this mode, hot reload will reset the full state to the default value defined in your code.