Skip to content

Commit 3118402

Browse files
committed
do not use react lazy
1 parent bf49c88 commit 3118402

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

reflex/compiler/templates.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ def context_template(
378378
return ({{ children, ...props }}) => {{
379379
const [Component, setComponent] = useState(null);
380380
useEffect(() => {{
381-
setComponent(component);
381+
async function load() {{
382+
const comp = await component();
383+
setComponent(() => comp);
384+
}}
385+
load();
382386
}}, []);
383387
return Component ? jsx(Component, props, children) : null;
384388
}};

reflex/components/component.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,6 @@ def _get_imports(self) -> ParsedImportDict:
22322232
"""
22332233
# React lazy import mechanism.
22342234
dynamic_import = {
2235-
"react": [ImportVar(tag="lazy")],
22362235
f"$/{constants.Dirs.UTILS}/context": [ImportVar(tag="ClientSide")],
22372236
}
22382237

@@ -2268,10 +2267,10 @@ def _get_dynamic_imports(self) -> str:
22682267
else ".then((mod) => mod.default)"
22692268
)
22702269
return (
2271-
f"const {self.alias or self.tag} = ClientSide(lazy(() => "
2270+
f"const {self.alias or self.tag} = ClientSide(() => "
22722271
+ library_import
22732272
+ mod_import
2274-
+ "))"
2273+
+ ")"
22752274
)
22762275

22772276

reflex/components/plotly/plotly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ def dynamic_plotly_import(name: str, package: str) -> str:
290290
library_import = f"import('{package}')"
291291
mod_import = ".then((mod) => ({ default: createPlotlyComponent(mod) }))"
292292
return f"""
293-
const {name} = ClientSide(lazy(() =>
293+
const {name} = ClientSide(() =>
294294
{library_import}{mod_import}
295-
))
295+
)
296296
"""
297297

298298

0 commit comments

Comments
 (0)