Avoid frontend errors with getRefValue (#2691)

This commit is contained in:
Masen Furer 2024-02-26 19:38:02 -08:00 committed by GitHub
parent 350a051a45
commit fc874e2ece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -178,7 +178,9 @@ export const applyEvent = async (event, socket) => {
if (event.name == "_set_value") { if (event.name == "_set_value") {
const ref = const ref =
event.payload.ref in refs ? refs[event.payload.ref] : event.payload.ref; event.payload.ref in refs ? refs[event.payload.ref] : event.payload.ref;
ref.current.value = event.payload.value; if (ref.current) {
ref.current.value = event.payload.value;
}
return false; return false;
} }
@ -627,14 +629,18 @@ export const getRefValue = (ref) => {
} }
if (ref.current.type == "checkbox") { if (ref.current.type == "checkbox") {
return ref.current.checked; // chakra return ref.current.checked; // chakra
} else if (ref.current.className.includes("rt-CheckboxButton") || ref.current.className.includes("rt-SwitchButton")) { } else if (ref.current.className?.includes("rt-CheckboxButton") || ref.current.className?.includes("rt-SwitchButton")) {
return ref.current.ariaChecked == "true"; // radix return ref.current.ariaChecked == "true"; // radix
} else if (ref.current.className.includes("rt-SliderRoot")) { } else if (ref.current.className?.includes("rt-SliderRoot")) {
// find the actual slider // find the actual slider
return ref.current.querySelector(".rt-SliderThumb").ariaValueNow; return ref.current.querySelector(".rt-SliderThumb")?.ariaValueNow;
} else { } else {
//querySelector(":checked") is needed to get value from radio_group //querySelector(":checked") is needed to get value from radio_group
return ref.current.value || (ref.current.querySelector(':checked') && ref.current.querySelector(':checked').value); return ref.current.value || (
ref.current.querySelector
&& ref.current.querySelector(':checked')
&& ref.current.querySelector(':checked')?.value
);
} }
} }