Browse Source

Catch a JS Error + code cleanup (#384)

Thomas Brandého 2 năm trước cách đây
mục cha
commit
39732d12f5

+ 25 - 0
pynecone/components/media/icon.py

@@ -13,3 +13,28 @@ class Icon(ChakraIconComponent):
     """An image icon."""
     """An image icon."""
 
 
     tag = "None"
     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)

+ 2 - 2
pynecone/middleware/hydrate_middleware.py

@@ -27,9 +27,9 @@ class HydrateMiddleware(Middleware):
             An optional state to return.
             An optional state to return.
         """
         """
         if event.name == utils.get_hydrate_event(state):
         if event.name == utils.get_hydrate_event(state):
-            route = event.router_data.get("pathname", "")
+            route = event.router_data.get(constants.RouteVar.PATH, "")
             if route == "/":
             if route == "/":
-                load_event = app.load_events.get("index")
+                load_event = app.load_events.get(constants.INDEX_ROUTE)
             elif route:
             elif route:
                 load_event = app.load_events.get(route.lstrip("/"))
                 load_event = app.load_events.get(route.lstrip("/"))
             else:
             else: