Skip to content

Commit 2b7f211

Browse files
authored
do not use react lazy (#6033)
* do not use react lazy * how about this * how about this
1 parent bf49c88 commit 2b7f211

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

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: 3 additions & 4 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

@@ -2265,13 +2264,13 @@ def _get_dynamic_imports(self) -> str:
22652264
# https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#with-named-exports
22662265
f".then((mod) => mod.{self.tag})"
22672266
if not self.is_default
2268-
else ".then((mod) => mod.default)"
2267+
else ".then((mod) => mod.default.default ?? 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ def dynamic_plotly_import(name: str, package: str) -> str:
288288
The dynamic import for the plotly component.
289289
"""
290290
library_import = f"import('{package}')"
291-
mod_import = ".then((mod) => ({ default: createPlotlyComponent(mod) }))"
291+
mod_import = ".then((mod) => 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)