Skip to content

Commit 2be3a88

Browse files
authored
exit gracefully when set_focus is passed a nonexistent argument (#5149)
1 parent d49fb5b commit 2be3a88

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

reflex/.templates/web/utils/state.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ export const queueEventIfSocketExists = async (events, socket) => {
178178
export const applyEvent = async (event, socket) => {
179179
// Handle special events
180180
if (event.name == "_redirect") {
181+
if ((event.payload.path ?? undefined) === undefined) {
182+
return false;
183+
}
181184
if (event.payload.external) {
182185
window.open(event.payload.path, "_blank", "noopener");
183186
} else if (event.payload.replace) {
@@ -240,7 +243,14 @@ export const applyEvent = async (event, socket) => {
240243
if (event.name == "_set_focus") {
241244
const ref =
242245
event.payload.ref in refs ? refs[event.payload.ref] : event.payload.ref;
243-
ref.current.focus();
246+
const focus = ref?.current?.focus;
247+
if (focus === undefined) {
248+
console.error(
249+
`No element found for ref ${event.payload.ref} in _set_focus`,
250+
);
251+
} else {
252+
focus();
253+
}
244254
return false;
245255
}
246256

0 commit comments

Comments
 (0)