Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict between _get_all_hooks and _get_all_hooks_internal #4516

Open
masenf opened this issue Dec 10, 2024 · 1 comment
Open

Conflict between _get_all_hooks and _get_all_hooks_internal #4516

masenf opened this issue Dec 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@masenf
Copy link
Collaborator

masenf commented Dec 10, 2024

Describe the bug
Hook code snippets that are returned by both _get_all_hooks and _get_all_hooks_internal are not de-duplicated, which can lead to rendering problems when const declarations are re-defined.

To Reproduce

import reflex as rx


class State(rx.State):
    """The app state."""
    v: str = "v"


class Foo(rx.Fragment):
    bar: rx.Var[str]

    def add_hooks(self) -> list[str]:
        return [
            rx.Var(f"console.log({self.bar})")
        ]

    def render(self):
        return {}


def index() -> rx.Component:
    return Foo.create(bar=State.v)


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

Expected behavior
All hooks code should always be de-duplicated.

Specifics (please complete the following information):

  • Python Version: 3.12
  • Reflex Version: 0.6.7.dev1
  • OS: macOS
  • Browser (Optional): chrome

Additional context
Care should be taken in regard to hook ordering (internal should always come first) and avoiding extra recursive calls (don't call _get_all_hooks_internal inside _get_all_hooks to avoid performance implications)

Copy link

linear bot commented Dec 10, 2024

@Lendemor Lendemor added the bug Something isn't working label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants