Catch a JS Error + code cleanup (#384)

This commit is contained in:
Thomas Brandého 2023-01-30 01:00:02 +01:00 committed by GitHub
parent 1ab8620852
commit 39732d12f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

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

View File

@ -27,9 +27,9 @@ class HydrateMiddleware(Middleware):
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: