Fix non-default imports for NoSSRComponent (#1548)

This commit is contained in:
Masen Furer 2023-08-15 17:32:23 -07:00 committed by GitHub
parent 2ff823e89a
commit 2eefb5d26c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

@ -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))

View File

@ -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]

View File

@ -15,6 +15,8 @@ class ReactPlayerComponent(NoSSRComponent):
tag = "ReactPlayer"
is_default = True
# The url of a video or song to play
url: Var[str]