Skip to content

Commit 5161944

Browse files
authored
make tag immutable (#5641)
* make tag immutable * ignore special props * fix plotly
1 parent f8e7b86 commit 5161944

File tree

14 files changed

+112
-96
lines changed

14 files changed

+112
-96
lines changed

reflex/components/component.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,6 @@ def render(self) -> dict:
12711271
tag.set(
12721272
children=[child.render() for child in self.children],
12731273
contents=str(tag.contents),
1274-
props=tag.format_props(),
12751274
)
12761275
)
12771276
self._replace_prop_names(rendered_dict)

reflex/components/core/clipboard.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ def _exclude_props(self) -> list[str]:
5656

5757
def _render(self) -> Tag:
5858
tag = super()._render()
59-
tag.remove_props("targets")
6059
# Ensure a different Fragment component is created whenever targets differ
61-
tag.add_props(key=self.targets)
62-
return tag
60+
return tag.remove_props("targets").add_props(key=self.targets)
6361

6462
def add_imports(self) -> dict[str, ImportVar]:
6563
"""Add the imports for the Clipboard component.

reflex/components/core/cond.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ def render(self) -> dict:
8080
sx=self.style,
8181
id=self.id,
8282
class_name=self.class_name,
83-
).set(
84-
props=tag.format_props(),
8583
),
8684
cond_state=str(self.cond),
8785
)

reflex/components/core/match.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ def render(self) -> dict:
256256
The dictionary for template of component.
257257
"""
258258
tag = self._render()
259-
tag.name = "match"
260-
return dict(tag)
259+
return dict(tag.set(name="match"))
261260

262261
def add_imports(self) -> ImportDict:
263262
"""Add imports for the Match component.

reflex/components/datadisplay/code.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,14 @@ def _render(self):
500500

501501
theme = self.theme
502502

503-
out.add_props(style=theme).remove_props("theme", "code").add_props(
504-
children=self.code,
503+
return (
504+
out.add_props(style=theme)
505+
.remove_props("theme", "code")
506+
.add_props(
507+
children=self.code,
508+
)
505509
)
506510

507-
return out
508-
509511

510512
class CodeblockNamespace(ComponentNamespace):
511513
"""Namespace for the CodeBlock component."""

reflex/components/el/elements/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def add_hooks(self) -> list[str]:
212212
def _render(self) -> Tag:
213213
render_tag = super()._render()
214214
if EventTriggers.ON_SUBMIT in self.event_triggers:
215-
render_tag.add_props(
215+
render_tag = render_tag.add_props(
216216
**{
217217
EventTriggers.ON_SUBMIT: Var(
218218
_js_expr=f"handleSubmit_{self.handle_submit_unique_name}",

reflex/components/plotly/plotly.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,24 @@ def _render(self):
245245
template_dict = LiteralVar.create({"layout": {"template": self.template}})
246246
merge_dicts.append(template_dict._without_data())
247247
if merge_dicts:
248-
tag.special_props.append(
249-
# Merge all dictionaries and spread the result over props.
250-
Var(
251-
_js_expr=f"{{...mergician({figure!s},"
252-
f"{','.join(str(md) for md in merge_dicts)})}}",
253-
),
248+
tag = tag.set(
249+
special_props=[
250+
*tag.special_props,
251+
# Merge all dictionaries and spread the result over props.
252+
Var(
253+
_js_expr=f"{{...mergician({figure!s},"
254+
f"{','.join(str(md) for md in merge_dicts)})}}",
255+
),
256+
]
254257
)
255258
else:
256-
# Spread the figure dict over props, nothing to merge.
257-
tag.special_props.append(Var(_js_expr=f"{figure!s}"))
259+
tag = tag.set(
260+
special_props=[
261+
*tag.special_props,
262+
# Spread the figure dict over props, nothing to merge.
263+
Var(_js_expr=str(figure)),
264+
]
265+
)
258266
return tag
259267

260268

reflex/components/radix/themes/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,11 @@ def add_imports(self) -> ImportDict | list[ImportDict]:
246246

247247
def _render(self, props: dict[str, Any] | None = None) -> Tag:
248248
tag = super()._render(props)
249-
tag.add_props(
249+
return tag.add_props(
250250
css=Var(
251251
_js_expr="{...theme.styles.global[':root'], ...theme.styles.global.body}"
252252
),
253-
)
254-
tag.remove_props("appearance")
255-
return tag
253+
).remove_props("appearance")
256254

257255

258256
class ThemePanel(RadixThemesComponent):

reflex/components/tags/cond_tag.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""Tag to conditionally render components."""
22

33
import dataclasses
4+
from collections.abc import Mapping
45
from typing import Any
56

67
from reflex.components.tags.tag import Tag
78
from reflex.vars.base import Var
89

910

10-
@dataclasses.dataclass()
11+
@dataclasses.dataclass(frozen=True)
1112
class CondTag(Tag):
1213
"""A conditional tag."""
1314

1415
# The condition to determine which component to render.
1516
cond: Var[Any] = dataclasses.field(default_factory=lambda: Var.create(True))
1617

1718
# The code to render if the condition is true.
18-
true_value: dict = dataclasses.field(default_factory=dict)
19+
true_value: Mapping = dataclasses.field(default_factory=dict)
1920

2021
# The code to render if the condition is false.
21-
false_value: dict | None = None
22+
false_value: Mapping | None = None

reflex/components/tags/iter_tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from reflex.components.component import Component
1717

1818

19-
@dataclasses.dataclass()
19+
@dataclasses.dataclass(frozen=True)
2020
class IterTag(Tag):
2121
"""An iterator tag."""
2222

0 commit comments

Comments
 (0)