Forráskód Böngészése

exit gracefully when set_focus is passed a nonexistent argument (#5149)

Khaleel Al-Adhami 3 hete
szülő
commit
2be3a884bc
1 módosított fájl, 11 hozzáadás és 1 törlés
  1. 11 1
      reflex/.templates/web/utils/state.js

+ 11 - 1
reflex/.templates/web/utils/state.js

@@ -178,6 +178,9 @@ export const queueEventIfSocketExists = async (events, socket) => {
 export const applyEvent = async (event, socket) => {
   // Handle special events
   if (event.name == "_redirect") {
+    if ((event.payload.path ?? undefined) === undefined) {
+      return false;
+    }
     if (event.payload.external) {
       window.open(event.payload.path, "_blank", "noopener");
     } else if (event.payload.replace) {
@@ -240,7 +243,14 @@ export const applyEvent = async (event, socket) => {
   if (event.name == "_set_focus") {
     const ref =
       event.payload.ref in refs ? refs[event.payload.ref] : event.payload.ref;
-    ref.current.focus();
+    const focus = ref?.current?.focus;
+    if (focus === undefined) {
+      console.error(
+        `No element found for ref ${event.payload.ref} in _set_focus`,
+      );
+    } else {
+      focus();
+    }
     return false;
   }