Skip to content

[REF-3239] Var dependency bug #3595

Closed

Description

@benedikt-bartscher

Describe the bug
Vars dependencies are not invalidated correctly

To Reproduce

import reflex as rx


class State(rx.State):
    @rx.var(cache=True)
    def id(self) -> str:
        return self.router.page.params.get("id", "")

    @rx.var(cache=True)
    def title(self) -> str:
        return f"Page {self.id}"


def index() -> rx.Component:
    return rx.container(
        rx.text(f"id: {State.id}"),
        rx.text(f"title: {State.title}"),
    )


app = rx.App()
app.add_page(index, route="/[id]")

Expected behavior
the pages displays "id: hello" and "title: hello"

Specifics (please complete the following information):

  • Python Version: 3.12.4
  • Reflex Version: main
  • OS: arch

REF-3239

Activity

  1. added
    bug
    on Jun 29, 2024
  2. alexlausz commented on Jun 30, 2024

    @alexlausz

    try this:

    class State(rx.State):
        @rx.cached_var
        def id(self) -> str:
            return self.router.page.params.get("id", "")
    
        @rx.var
        def title(self) -> str:
            return f"Page {self.id}"
    
  3. benedikt-bartscher commented on Jun 30, 2024

    @benedikt-bartscher
    ContributorAuthor

    @alexlausz you must be trolling. You are suggesting to disable var caching, but this issue is about a bug in var caching.
    It's like telling someone who has an issue with cruise control in their car to just disable it and control the speed manually.

  4. changed the title [-]Var dependency bug[/-] [+][REF-3239] Var dependency bug[/+] on Jul 3, 2024
  5. abulvenz commented on Aug 26, 2024

    @abulvenz
    Contributor

    This is important, because many var trees root in router.

  6. benedikt-bartscher commented on Aug 26, 2024

    @benedikt-bartscher
    ContributorAuthor

    The example from the issue description was actually affected by shadowing (#3805 revealed it). id was overwritten by the uncached dynamically created route var.
    Cached vars depending on BaseState.router do not work at all.

  7. added this to the milestone on Sep 9, 2024
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions