From 2eefb5d26cfe0ceea6d683a97a4fd35b32d2fc5f Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Tue, 15 Aug 2023 17:32:23 -0700 Subject: [PATCH] Fix non-default imports for NoSSRComponent (#1548) --- reflex/components/component.py | 8 +++++++- reflex/components/graphing/plotly.py | 2 ++ reflex/components/libs/react_player.py | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/reflex/components/component.py b/reflex/components/component.py index 841de73d6..753c59741 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -799,4 +799,10 @@ class NoSSRComponent(Component): def _get_custom_code(self) -> str: opts_fragment = ", { ssr: false });" library_import = f"const {self.tag} = dynamic(() => import('{self.library}')" - return "".join((library_import, opts_fragment)) + mod_import = ( + # https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#with-named-exports + f".then((mod) => mod.{self.tag})" + if not self.is_default + else "" + ) + return "".join((library_import, mod_import, opts_fragment)) diff --git a/reflex/components/graphing/plotly.py b/reflex/components/graphing/plotly.py index 4af915634..654cf6ee9 100644 --- a/reflex/components/graphing/plotly.py +++ b/reflex/components/graphing/plotly.py @@ -20,6 +20,8 @@ class Plotly(PlotlyLib): tag = "Plot" + is_default = True + # The figure to display. This can be a plotly figure or a plotly data json. data: Var[Figure] diff --git a/reflex/components/libs/react_player.py b/reflex/components/libs/react_player.py index 65f752f28..fef1c583c 100644 --- a/reflex/components/libs/react_player.py +++ b/reflex/components/libs/react_player.py @@ -15,6 +15,8 @@ class ReactPlayerComponent(NoSSRComponent): tag = "ReactPlayer" + is_default = True + # The url of a video or song to play url: Var[str]