-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Advanced Settings] Fix code editor field #177772
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,14 +90,17 @@ export const CodeEditorInput = ({ | |
); | ||
|
||
const debouncedUpdateValue = useMemo(() => { | ||
// Trigger update 1000 ms after the user stopped typing to reduce validation requests to the server | ||
return debounce(updateValue, 1000); | ||
// Trigger update 500 ms after the user stopped typing to reduce validation requests to the server | ||
return debounce(updateValue, 500); | ||
}, [updateValue]); | ||
|
||
const onChange: CodeEditorProps['onChange'] = async (newValue) => { | ||
// @ts-expect-error | ||
setValue(newValue); | ||
await debouncedUpdateValue(newValue, onUpdate); | ||
// Only update the value when the onChange handler is called with a different value from the current one | ||
if (newValue !== value) { | ||
// @ts-expect-error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious why there is a TS error here and if we could fix it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review @yuliacech! I see that there are two TS errors in the code editor component and I think they are caused because this component is used by both json and markdown type settings, while the |
||
setValue(newValue); | ||
await debouncedUpdateValue(newValue, onUpdate); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to reduce the debounce period?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The debounce period is set to 500 for the other field types and I initially set it to 1000 for the code editor to allow more time for the user to finish typing in, but later I realised that with a longer period there is a higher risk of the user clicking on the Save/reset button before the period is over. So I decided to make it 500 as the rest of the fields.