Skip to content

Commit

Permalink
Catch a JS Error + code cleanup (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor committed Jan 30, 2023
1 parent 1ab8620 commit 39732d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions pynecone/components/media/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ class Icon(ChakraIconComponent):
"""An image icon."""

tag = "None"

@classmethod
def create(cls, *children, **props):
"""Initialize the Icon component.
Run some additional checks on Icon component.
Args:
children: The positional arguments
props: The keyword arguments
Raises:
AttributeError: The errors tied to bad usage of the Icon component.
Returns:
The created component.
"""
if children:
raise AttributeError(
f"Passing children to Icon component is not allowed: remove positional arguments {children} to fix"
)
if "tag" not in props.keys():
raise AttributeError("Missing 'tag' keyword-argument for Icon")

return super().create(*children, **props)
4 changes: 2 additions & 2 deletions pynecone/middleware/hydrate_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def preprocess(self, app: App, state: State, event: Event) -> Optional[Delta]:
An optional state to return.
"""
if event.name == utils.get_hydrate_event(state):
route = event.router_data.get("pathname", "")
route = event.router_data.get(constants.RouteVar.PATH, "")
if route == "/":
load_event = app.load_events.get("index")
load_event = app.load_events.get(constants.INDEX_ROUTE)
elif route:
load_event = app.load_events.get(route.lstrip("/"))
else:
Expand Down

0 comments on commit 39732d1

Please sign in to comment.