Skip to content

Commit bc1f718

Browse files
committed
fix possibly faulty local storage value error
1 parent 4ee1f5b commit bc1f718

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ function useLocalStorageStateWithURLDefault<T>(key: string, defaultValue: string
5656
}
5757
}
5858

59-
const parsedValue = schema.parse(urlValue ?? value)
59+
const parsedValue = schema.safeParse(urlValue ?? value)
6060

61-
return [parsedValue, modifiedSetValue] as const
61+
if (parsedValue.success) {
62+
return [parsedValue.data, modifiedSetValue] as const
63+
}
64+
65+
// if the value in localStorage is invalid then revert back to default
66+
setValue(defaultValue)
67+
return [defaultValue as T, modifiedSetValue] as const
6268
}
6369

6470
const ChatV2Content = () => {
@@ -74,6 +80,7 @@ const ChatV2Content = () => {
7480

7581
// local storage states
7682
const localStoragePrefix = courseId ? `course-${courseId}` : 'general'
83+
7784
const [activeModel, setActiveModel] = useLocalStorageStateWithURLDefault('model-v2', DEFAULT_MODEL, 'model', ValidModelNameSchema)
7885
const [disclaimerStatus, setDisclaimerStatus] = useLocalStorageState<boolean>('disclaimer-status', true)
7986
const [modelTemperature, setModelTemperature] = useLocalStorageStateWithURLDefault(

0 commit comments

Comments
 (0)