Skip to content

Commit c926b2f

Browse files
authored
When merging hook VarData, include the hook's VarData first (#5283)
* When merging hook VarData, include the hook's VarData first The hook's VarData might be referencing some earlier hooks that are needed, so include the dependent VarData first so the dependencies render earlier in the output and can be referenced. * Update test hook order expectation
1 parent e629000 commit c926b2f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

reflex/vars/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def __init__(
170170
object.__setattr__(self, "components", tuple(components or []))
171171

172172
if hooks and any(hooks.values()):
173-
merged_var_data = VarData.merge(self, *hooks.values())
173+
# Merge our dependencies first, so they can be referenced.
174+
merged_var_data = VarData.merge(*hooks.values(), self)
174175
if merged_var_data is not None:
175176
object.__setattr__(self, "state", merged_var_data.state)
176177
object.__setattr__(self, "field_name", merged_var_data.field_name)

tests/units/test_var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ def test_var_data_hooks():
18961896

18971897
def test_var_data_with_hooks_value():
18981898
var_data = VarData(hooks={"what": VarData(hooks={"whot": VarData(hooks="whott")})})
1899-
assert var_data == VarData(hooks=["what", "whot", "whott"])
1899+
assert var_data == VarData(hooks=["whott", "whot", "what"])
19001900

19011901

19021902
def test_str_var_in_components(mocker):

0 commit comments

Comments
 (0)