Fixes from testing on reflex-web
This commit is contained in:
parent
622f0f0dc8
commit
8643ccb758
@ -30,8 +30,8 @@ class Link(ChakraComponent):
|
||||
# If true, the link will open in new tab.
|
||||
is_external: Var[bool]
|
||||
|
||||
def _get_imports(self) -> imports.ImportDict:
|
||||
return {**super()._get_imports(), **next_link._get_imports()}
|
||||
def _get_imports_list(self) -> list[imports.ImportVar]:
|
||||
return [*super()._get_imports_list(), *next_link._get_imports_list()]
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, **props) -> Component:
|
||||
|
@ -1593,32 +1593,29 @@ memo = custom_component
|
||||
class NoSSRComponent(Component):
|
||||
"""A dynamic component that is not rendered on the server."""
|
||||
|
||||
def _get_imports(self) -> imports.ImportDict:
|
||||
def _get_imports_list(self) -> list[ImportVar]:
|
||||
"""Get the imports for the component.
|
||||
|
||||
Returns:
|
||||
The imports for dynamically importing the component at module load time.
|
||||
"""
|
||||
# Next.js dynamic import mechanism.
|
||||
dynamic_import = {"next/dynamic": [ImportVar(tag="dynamic", is_default=True)]}
|
||||
return [
|
||||
*super()._get_imports_list(),
|
||||
# Next.js dynamic import mechanism.
|
||||
ImportVar(package="next/dynamic", tag="dynamic", is_default=True),
|
||||
]
|
||||
|
||||
# The normal imports for this component.
|
||||
_imports = super()._get_imports()
|
||||
@property
|
||||
def import_var(self) -> ImportVar:
|
||||
"""Will not actually render the tag to import, get it dynamically instead.
|
||||
|
||||
# Do NOT import the main library/tag statically.
|
||||
if self.library is not None:
|
||||
_imports[self.library] = [
|
||||
imports.ImportVar(
|
||||
tag=None,
|
||||
render=False,
|
||||
transpile=self._should_transpile(self.library),
|
||||
),
|
||||
]
|
||||
|
||||
return imports.merge_imports(
|
||||
dynamic_import,
|
||||
_imports,
|
||||
)
|
||||
Returns:
|
||||
An import var.
|
||||
"""
|
||||
imp = super().import_var
|
||||
imp.tag = None
|
||||
imp.render = False
|
||||
return imp
|
||||
|
||||
def _get_dynamic_imports(self) -> str:
|
||||
opts_fragment = ", { ssr: false });"
|
||||
|
@ -112,7 +112,7 @@ class DebounceInput(Component):
|
||||
)._replace(
|
||||
_var_type=Type[Component],
|
||||
merge_var_data=VarData( # type: ignore
|
||||
imports=child._get_imports(),
|
||||
imports=child._get_imports_list(),
|
||||
hooks=child._get_hooks_internal(),
|
||||
),
|
||||
),
|
||||
|
@ -268,11 +268,11 @@ class Match(MemoizationLeaf):
|
||||
tag.name = "match"
|
||||
return dict(tag)
|
||||
|
||||
def _get_imports(self) -> imports.ImportDict:
|
||||
return imports.merge_imports(
|
||||
super()._get_imports(),
|
||||
getattr(self.cond._var_data, "imports", {}),
|
||||
)
|
||||
def _get_imports_list(self) -> list[imports.ImportVar]:
|
||||
return [
|
||||
*super()._get_imports_list(),
|
||||
*getattr(self.cond._var_data, "imports", []),
|
||||
]
|
||||
|
||||
def _apply_theme(self, theme: Component):
|
||||
"""Apply the theme to this component.
|
||||
|
@ -180,7 +180,7 @@ class Markdown(Component):
|
||||
is_default=True,
|
||||
),
|
||||
ImportVar(
|
||||
package="remark-katex@6.0.3",
|
||||
package="rehype-katex@6.0.3",
|
||||
tag=_REHYPE_KATEX._var_name,
|
||||
is_default=True,
|
||||
),
|
||||
|
@ -425,12 +425,12 @@ class AccordionRoot(AccordionComponent):
|
||||
accordion_theme_root
|
||||
)
|
||||
|
||||
def _get_imports(self):
|
||||
return imports.merge_imports(
|
||||
super()._get_imports(),
|
||||
self._var_data.imports if self._var_data else {},
|
||||
{"@emotion/react": [imports.ImportVar(tag="keyframes")]},
|
||||
)
|
||||
def _get_imports_list(self) -> list[imports.ImportVar]:
|
||||
return [
|
||||
*super()._get_imports_list(),
|
||||
*(self._var_data.imports if self._var_data else {}),
|
||||
imports.ImportVar(package="@emotion/react", tag="keyframes"),
|
||||
]
|
||||
|
||||
def get_event_triggers(self) -> Dict[str, Any]:
|
||||
"""Get the events triggers signatures for the component.
|
||||
@ -644,12 +644,6 @@ class AccordionContent(AccordionComponent):
|
||||
def _apply_theme(self, theme: Component):
|
||||
self.style = Style({**self.style})
|
||||
|
||||
# def _get_imports(self):
|
||||
# return {
|
||||
# **super()._get_imports(),
|
||||
# "@emotion/react": [imports.ImportVar(tag="keyframes")],
|
||||
# }
|
||||
|
||||
|
||||
class Accordion(ComponentNamespace):
|
||||
"""Accordion component."""
|
||||
|
@ -59,8 +59,8 @@ class Link(RadixThemesComponent, A, MemoizationLeaf):
|
||||
# If True, the link will open in a new tab
|
||||
is_external: Var[bool]
|
||||
|
||||
def _get_imports(self) -> imports.ImportDict:
|
||||
return {**super()._get_imports(), **next_link._get_imports()}
|
||||
def _get_imports_list(self) -> list[imports.ImportVar]:
|
||||
return [*super()._get_imports_list(), *next_link._get_imports_list()]
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, **props) -> Component:
|
||||
|
@ -22,6 +22,7 @@ from typing import (
|
||||
List,
|
||||
Literal,
|
||||
Optional,
|
||||
Sequence,
|
||||
Tuple,
|
||||
Type,
|
||||
Union,
|
||||
@ -129,7 +130,7 @@ class VarData(Base):
|
||||
def __init__(
|
||||
self,
|
||||
imports: ImportList
|
||||
| List[ImportVar | Dict[str, Optional[Union[str, bool]]]]
|
||||
| Sequence[ImportVar | Dict[str, Optional[Union[str, bool]]]]
|
||||
| ImportDict
|
||||
| Dict[str, set[ImportVar]]
|
||||
| None = None,
|
||||
|
@ -18,6 +18,7 @@ from typing import (
|
||||
Iterable,
|
||||
List,
|
||||
Optional,
|
||||
Sequence,
|
||||
Set,
|
||||
Tuple,
|
||||
Type,
|
||||
@ -41,7 +42,7 @@ class VarData(Base):
|
||||
def __init__(
|
||||
self,
|
||||
imports: ImportList
|
||||
| List[ImportVar | Dict[str, Optional[Union[str, bool]]]]
|
||||
| Sequence[ImportVar | Dict[str, Optional[Union[str, bool]]]]
|
||||
| ImportDict
|
||||
| Dict[str, set[ImportVar]]
|
||||
| None = None,
|
||||
|
Loading…
Reference in New Issue
Block a user