Skip to content

Commit 41dddef

Browse files
committed
add hot loop for _unsafe_create
1 parent b6f48d3 commit 41dddef

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

reflex/components/base/bare.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ def create(cls, contents: Any) -> Component:
7070
if isinstance(contents, Var):
7171
if isinstance(contents, LiteralStringVar):
7272
validate_str(contents._var_value)
73-
return cls._create(children=[], contents=contents)
73+
return cls._unsafe_create(children=[], contents=contents)
7474
else:
7575
if isinstance(contents, str):
7676
validate_str(contents)
77-
contents = str(contents) if contents is not None else ""
77+
contents = Var.create(contents if contents is not None else "")
7878

79-
return cls._create(children=[], contents=contents)
79+
return cls._unsafe_create(children=[], contents=contents)
8080

8181
def _get_all_hooks_internal(self) -> dict[str, VarData | None]:
8282
"""Include the hooks for the component.

reflex/components/component.py

+18
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,24 @@ def _create(cls: Type[T], children: Sequence[BaseComponent], **props: Any) -> T:
826826
comp._post_init(children=list(children), **props)
827827
return comp
828828

829+
@classmethod
830+
def _unsafe_create(
831+
cls: Type[T], children: Sequence[BaseComponent], **props: Any
832+
) -> T:
833+
"""Create the component without running post_init.
834+
835+
Args:
836+
children: The children of the component.
837+
**props: The props of the component.
838+
839+
Returns:
840+
The component.
841+
"""
842+
comp = cls.construct(id=props.get("id"), children=list(children))
843+
for prop, value in props.items():
844+
setattr(comp, prop, value)
845+
return comp
846+
829847
def add_style(self) -> dict[str, Any] | None:
830848
"""Add style to the component.
831849

0 commit comments

Comments
 (0)