🔧 fix: Apply Mongoose Plugin at Model Creation (#7749)

* fix: apply mongoMeili when models are created to use main runtime mongoose

* chore: update @librechat/data-schemas version to 0.0.8

* refactor: remove unused useDebounceCodeBlock

* fix: ensure setter function is stable and handle numeric conversion in useDebouncedInput

* refactor: replace useCallback with useMemo for stable debounced function in useDebouncedInput
This commit is contained in:
Danny Avila 2025-06-04 23:11:34 -04:00 committed by GitHub
parent be4cf5846c
commit dff4fcac00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 40 additions and 73 deletions

View file

@ -1,5 +1,5 @@
import debounce from 'lodash/debounce';
import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useMemo } from 'react';
import type { SetterOrUpdater } from 'recoil';
import type { TSetOption } from '~/common';
import { defaultDebouncedDelay } from '~/common';
@ -29,10 +29,10 @@ function useDebouncedInput<T = unknown>({
/** A debounced function to call the passed setOption with the optionKey and new value.
*
Note: We use useCallback to ensure our debounced function is stable across renders. */
const setDebouncedOption = useCallback(
debounce(setOption && optionKey ? setOption(optionKey) : setter, delay),
[],
Note: We use useMemo to ensure our debounced function is stable across renders and properly typed. */
const setDebouncedOption = useMemo(
() => debounce(setOption && optionKey ? setOption(optionKey) : setter || (() => {}), delay),
[setOption, optionKey, setter, delay],
);
/** An onChange handler that updates the local state and the debounced option */
@ -42,8 +42,9 @@ function useDebouncedInput<T = unknown>({
typeof e !== 'object'
? e
: ((e as React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>).target
.value as unknown as T);
if (numeric === true) {
.value as unknown as T);
// Handle numeric conversion only if value is not undefined and not empty string
if (numeric === true && newValue !== undefined && newValue !== '') {
newValue = Number(newValue) as unknown as T;
}
setValue(newValue);