Skip to content

Commit a5c73ad

Browse files
adhami3310samarth9201ElijahAhianyomasenfbenedikt-bartscher
authored
Use old serializer system in LiteralVar (#3875)
* use serializer system * add checks for unsupported operands * and and or are now supported * format * remove unnecessary call to JSON * put base before rest * fix failing testcase * add hinting to get static analysis to complain * damn * big changes * get typeguard from extensions * please darglint * dangit darglint * remove one from vars * add without data and use it in plotly * DARGLINT * change format for special props * add pyi * delete instances of Var.create * modify client state to work * fixed so much * remove every Var.create * delete all basevar stuff * checkpoint * fix pyi * get older python to work * dangit darglint * add simple fix to last failing testcase * remove var name unwrapped and put client state on immutable var * fix older python * fox event issues * change forms pyi * make test less strict * use rx state directly * add typeignore to page_id * implement foreach * delete .web states folder silly * update reflex chakra * fix issue when on mount or on unmount is not set * nuke Var * run pyi * import immutablevar in critical location * delete unwrap vars * bring back array ref * fix style props in app * /health endpoint for K8 Liveness and Readiness probes (#3855) * Added API Endpoint * Added API Endpoint * Added Unit Tests * Added Unit Tests * main * Apply suggestions from Code Review * Fix Ruff Formatting * Update Socket Events * Async Functions * Update find_replace (#3886) * [REF-3592]Promote `rx.progress` from radix themes (#3878) * Promote `rx.progress` from radix themes * fix pyi * add warning when accessing `rx._x.progress` * Use correct flexgen backend URL (#3891) * Remove demo template (#3888) * gitignore .web (#3885) * update overflowY in AUTO_HEIGHT_JS from hidden to scroll (#3882) * Retain mutability inside `async with self` block (#3884) When emitting a state update, restore `_self_mutable` to the value it had previously so that `yield` in the middle of `async with self` does not result in an immutable StateProxy. Fix #3869 * Include child imports in markdown component_map (#3883) If a component in the markdown component_map contains children components, use `_get_all_imports` to recursively enumerate them. Fix #3880 * [REF-3570] Remove deprecated REDIS_URL syntax (#3892) * mixin computed vars should only be applied to highest level state (#3833) * improve state hierarchy validation, drop old testing special case (#3894) * fix var dependency dicts (#3842) * Adding array to array pluck operation. (#3868) * fix initial state without cv fallback (#3670) * add fragment to foreach (#3877) * Update docker-example (#3324) * /health endpoint for K8 Liveness and Readiness probes (#3855) * Added API Endpoint * Added API Endpoint * Added Unit Tests * Added Unit Tests * main * Apply suggestions from Code Review * Fix Ruff Formatting * Update Socket Events * Async Functions * /health endpoint for K8 Liveness and Readiness probes (#3855) * Added API Endpoint * Added API Endpoint * Added Unit Tests * Added Unit Tests * main * Apply suggestions from Code Review * Fix Ruff Formatting * Update Socket Events * Async Functions * Merge branch 'main' into use-old-serializer-in-literalvar * [REF-3570] Remove deprecated REDIS_URL syntax (#3892) * /health endpoint for K8 Liveness and Readiness probes (#3855) * Added API Endpoint * Added API Endpoint * Added Unit Tests * Added Unit Tests * main * Apply suggestions from Code Review * Fix Ruff Formatting * Update Socket Events * Async Functions * [REF-3570] Remove deprecated REDIS_URL syntax (#3892) * remove extra var Co-authored-by: Masen Furer <m_github@0x26.net> * resolve typo * write better doc for var.create * return var value when we know it's literal var * fix unit test * less bloat for ToOperations * simplify ImmutableComputedVar.__get__ (#3902) * simplify ImmutableComputedVar.__get__ * ruff it --------- Co-authored-by: Samarth Bhadane <samarthbhadane119@gmail.com> Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com> Co-authored-by: Masen Furer <m_github@0x26.net> Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com> Co-authored-by: Vishnu Deva <vishnu.deva12@gmail.com> Co-authored-by: abulvenz <a.eismann@senbax.de>
1 parent fb721e1 commit a5c73ad

182 files changed

Lines changed: 13597 additions & 11316 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration/test_dynamic_routes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def DynamicRoute():
2323

2424
class DynamicState(rx.State):
2525
order: List[str] = []
26-
page_id: str = ""
2726

2827
def on_load(self):
2928
self.order.append(f"{self.router.page.path}-{self.page_id or 'no page id'}")
@@ -47,7 +46,7 @@ def index():
4746
is_read_only=True,
4847
id="token",
4948
),
50-
rc.input(value=DynamicState.page_id, is_read_only=True, id="page_id"),
49+
rc.input(value=rx.State.page_id, is_read_only=True, id="page_id"), # type: ignore
5150
rc.input(
5251
value=DynamicState.router.page.raw_path,
5352
is_read_only=True,
@@ -74,9 +73,9 @@ def redirect_page():
7473
return rx.fragment(rx.text("redirecting..."))
7574

7675
app = rx.App(state=rx.State)
77-
app.add_page(index)
7876
app.add_page(index, route="/page/[page_id]", on_load=DynamicState.on_load) # type: ignore
7977
app.add_page(index, route="/static/x", on_load=DynamicState.on_load) # type: ignore
78+
app.add_page(index)
8079
app.add_custom_404_page(on_load=DynamicState.on_load) # type: ignore
8180

8281

integration/test_tailwind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_tailwind_app(tailwind_app: AppHarness, tailwind_disabled: bool):
109109
assert len(paragraphs) == 3
110110
for p in paragraphs:
111111
assert tailwind_app.poll_for_content(p, exp_not_equal="") == PARAGRAPH_TEXT
112-
assert p.value_of_css_property("font-family") == '"monospace"'
112+
assert p.value_of_css_property("font-family") == "monospace"
113113
if tailwind_disabled:
114114
# expect default color, not "text-red-500" from tailwind utility class
115115
assert p.value_of_css_property("color") not in TEXT_RED_500_COLOR

poetry.lock

Lines changed: 317 additions & 315 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reflex/.templates/jinja/web/pages/utils.js.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
{% macro render_match_tag(component) %}
8686
{
8787
(() => {
88-
switch (JSON.stringify({{ component.cond._var_name_unwrapped }})) {
88+
switch (JSON.stringify({{ component.cond._var_name }})) {
8989
{% for case in component.match_cases %}
9090
{% for condition in case[:-1] %}
91-
case JSON.stringify({{ condition._var_name_unwrapped }}):
91+
case JSON.stringify({{ condition._var_name }}):
9292
{% endfor %}
9393
return {{ case[-1] }};
9494
break;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default {{ theme|json_dumps }}
1+
export default {{ theme }}

reflex/compiler/compiler.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
StatefulComponent,
1818
)
1919
from reflex.config import get_config
20-
from reflex.ivars.base import LiteralVar
20+
from reflex.ivars.base import ImmutableVar, LiteralVar
2121
from reflex.state import BaseState
2222
from reflex.style import SYSTEM_COLOR_MODE
2323
from reflex.utils.exec import is_prod_mode
2424
from reflex.utils.imports import ImportVar
2525
from reflex.utils.prerequisites import get_web_dir
26-
from reflex.vars import Var
2726

2827

2928
def _compile_document_root(root: Component) -> str:
@@ -58,7 +57,7 @@ def _compile_app(app_root: Component) -> str:
5857
)
5958

6059

61-
def _compile_theme(theme: dict) -> str:
60+
def _compile_theme(theme: str) -> str:
6261
"""Compile the theme.
6362
6463
Args:
@@ -321,7 +320,7 @@ def _compile_tailwind(
321320
def compile_document_root(
322321
head_components: list[Component],
323322
html_lang: Optional[str] = None,
324-
html_custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
323+
html_custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
325324
) -> tuple[str, str]:
326325
"""Compile the document root.
327326
@@ -378,7 +377,7 @@ def compile_theme(style: ComponentStyle) -> tuple[str, str]:
378377
theme = utils.create_theme(style)
379378

380379
# Compile the theme.
381-
code = _compile_theme(theme)
380+
code = _compile_theme(str(LiteralVar.create(theme)))
382381
return output_path, code
383382

384383

reflex/compiler/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any, Callable, Dict, Optional, Type, Union
88
from urllib.parse import urlparse
99

10+
from reflex.ivars.base import ImmutableVar
1011
from reflex.utils.prerequisites import get_web_dir
1112

1213
try:
@@ -32,7 +33,6 @@
3233
from reflex.style import Style
3334
from reflex.utils import console, format, imports, path_ops
3435
from reflex.utils.imports import ImportVar, ParsedImportDict
35-
from reflex.vars import Var
3636

3737
# To re-export this function.
3838
merge_imports = imports.merge_imports
@@ -286,7 +286,7 @@ def compile_custom_component(
286286
def create_document_root(
287287
head_components: list[Component] | None = None,
288288
html_lang: Optional[str] = None,
289-
html_custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
289+
html_custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
290290
) -> Component:
291291
"""Create the document root.
292292

reflex/components/base/app_wrap.pyi

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ from typing import Any, Callable, Dict, Optional, Union, overload
77

88
from reflex.components.base.fragment import Fragment
99
from reflex.event import EventHandler, EventSpec
10+
from reflex.ivars.base import ImmutableVar
1011
from reflex.style import Style
11-
from reflex.vars import Var
1212

1313
class AppWrap(Fragment):
1414
@overload
@@ -21,41 +21,51 @@ class AppWrap(Fragment):
2121
id: Optional[Any] = None,
2222
class_name: Optional[Any] = None,
2323
autofocus: Optional[bool] = None,
24-
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
25-
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
26-
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
24+
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
25+
on_blur: Optional[
26+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
27+
] = None,
28+
on_click: Optional[
29+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
30+
] = None,
2731
on_context_menu: Optional[
28-
Union[EventHandler, EventSpec, list, Callable, Var]
32+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
2933
] = None,
3034
on_double_click: Optional[
31-
Union[EventHandler, EventSpec, list, Callable, Var]
35+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
36+
] = None,
37+
on_focus: Optional[
38+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
39+
] = None,
40+
on_mount: Optional[
41+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
3242
] = None,
33-
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
34-
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
3543
on_mouse_down: Optional[
36-
Union[EventHandler, EventSpec, list, Callable, Var]
44+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
3745
] = None,
3846
on_mouse_enter: Optional[
39-
Union[EventHandler, EventSpec, list, Callable, Var]
47+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4048
] = None,
4149
on_mouse_leave: Optional[
42-
Union[EventHandler, EventSpec, list, Callable, Var]
50+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4351
] = None,
4452
on_mouse_move: Optional[
45-
Union[EventHandler, EventSpec, list, Callable, Var]
53+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4654
] = None,
4755
on_mouse_out: Optional[
48-
Union[EventHandler, EventSpec, list, Callable, Var]
56+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4957
] = None,
5058
on_mouse_over: Optional[
51-
Union[EventHandler, EventSpec, list, Callable, Var]
59+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
5260
] = None,
5361
on_mouse_up: Optional[
54-
Union[EventHandler, EventSpec, list, Callable, Var]
62+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
63+
] = None,
64+
on_scroll: Optional[
65+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
5566
] = None,
56-
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
5767
on_unmount: Optional[
58-
Union[EventHandler, EventSpec, list, Callable, Var]
68+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
5969
] = None,
6070
**props,
6171
) -> "AppWrap":

reflex/components/base/bare.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ def create(cls, contents: Any) -> Component:
2828
"""
2929
if isinstance(contents, ImmutableVar):
3030
return cls(contents=contents)
31-
if isinstance(contents, Var):
32-
contents = contents.to(str)
3331
else:
3432
contents = str(contents) if contents is not None else ""
3533
return cls(contents=contents) # type: ignore
@@ -39,7 +37,7 @@ def _render(self) -> Tag:
3937
return Tagless(contents=f"{{{str(self.contents)}}}")
4038
return Tagless(contents=str(self.contents))
4139

42-
def _get_vars(self, include_children: bool = False) -> Iterator[Var]:
40+
def _get_vars(self, include_children: bool = False) -> Iterator[ImmutableVar]:
4341
"""Walk all Vars used in this component.
4442
4543
Args:

reflex/components/base/body.pyi

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ from typing import Any, Callable, Dict, Optional, Union, overload
77

88
from reflex.components.component import Component
99
from reflex.event import EventHandler, EventSpec
10+
from reflex.ivars.base import ImmutableVar
1011
from reflex.style import Style
11-
from reflex.vars import Var
1212

1313
class Body(Component):
1414
@overload
@@ -21,41 +21,51 @@ class Body(Component):
2121
id: Optional[Any] = None,
2222
class_name: Optional[Any] = None,
2323
autofocus: Optional[bool] = None,
24-
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
25-
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
26-
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
24+
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
25+
on_blur: Optional[
26+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
27+
] = None,
28+
on_click: Optional[
29+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
30+
] = None,
2731
on_context_menu: Optional[
28-
Union[EventHandler, EventSpec, list, Callable, Var]
32+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
2933
] = None,
3034
on_double_click: Optional[
31-
Union[EventHandler, EventSpec, list, Callable, Var]
35+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
36+
] = None,
37+
on_focus: Optional[
38+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
39+
] = None,
40+
on_mount: Optional[
41+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
3242
] = None,
33-
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
34-
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
3543
on_mouse_down: Optional[
36-
Union[EventHandler, EventSpec, list, Callable, Var]
44+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
3745
] = None,
3846
on_mouse_enter: Optional[
39-
Union[EventHandler, EventSpec, list, Callable, Var]
47+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4048
] = None,
4149
on_mouse_leave: Optional[
42-
Union[EventHandler, EventSpec, list, Callable, Var]
50+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4351
] = None,
4452
on_mouse_move: Optional[
45-
Union[EventHandler, EventSpec, list, Callable, Var]
53+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4654
] = None,
4755
on_mouse_out: Optional[
48-
Union[EventHandler, EventSpec, list, Callable, Var]
56+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
4957
] = None,
5058
on_mouse_over: Optional[
51-
Union[EventHandler, EventSpec, list, Callable, Var]
59+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
5260
] = None,
5361
on_mouse_up: Optional[
54-
Union[EventHandler, EventSpec, list, Callable, Var]
62+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
63+
] = None,
64+
on_scroll: Optional[
65+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
5566
] = None,
56-
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
5767
on_unmount: Optional[
58-
Union[EventHandler, EventSpec, list, Callable, Var]
68+
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
5969
] = None,
6070
**props,
6171
) -> "Body":

0 commit comments

Comments
 (0)