mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 01:11:13 -05:00
Improve error handling and stability across the application
Refactor error handling in `useEntityVersions` and `useSearch` hooks, enhance `NotificationService` with better error extraction and logging, and implement critical fallback mechanisms in the `detect-location` function's rate limit cleanup. Update CORS configuration in `upload-image` function for stricter origin checks and better security. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f4df1950-6410-48d0-b2de-f4096732504b Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -27,7 +27,7 @@ const DEFAULT_MIN_QUERY = 2;
|
||||
const DEFAULT_DEBOUNCE_MS = 300;
|
||||
|
||||
export function useSearch(options: UseSearchOptions = {}) {
|
||||
// State declarations MUST come first to maintain hook order
|
||||
// All hooks declarations in stable order
|
||||
const [query, setQuery] = useState('');
|
||||
const [results, setResults] = useState<SearchResult[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -35,15 +35,17 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
const [recentSearches, setRecentSearches] = useState<string[]>([]);
|
||||
const [debouncedQuery, setDebouncedQuery] = useState('');
|
||||
|
||||
// Stabilize options using JSON stringify to prevent infinite loops from array recreation
|
||||
const optionsKey = JSON.stringify({
|
||||
types: options.types || DEFAULT_TYPES,
|
||||
limit: options.limit || DEFAULT_LIMIT,
|
||||
minQuery: options.minQuery || DEFAULT_MIN_QUERY,
|
||||
debounceMs: options.debounceMs || DEFAULT_DEBOUNCE_MS
|
||||
});
|
||||
// Use useMemo to stabilize options, but use safe defaults to prevent undefined errors during HMR
|
||||
const stableOptions = useMemo(() => {
|
||||
const safeOptions = options || {};
|
||||
return {
|
||||
types: safeOptions.types || DEFAULT_TYPES,
|
||||
limit: safeOptions.limit ?? DEFAULT_LIMIT,
|
||||
minQuery: safeOptions.minQuery ?? DEFAULT_MIN_QUERY,
|
||||
debounceMs: safeOptions.debounceMs ?? DEFAULT_DEBOUNCE_MS,
|
||||
};
|
||||
}, [options]);
|
||||
|
||||
const stableOptions = useMemo(() => JSON.parse(optionsKey), [optionsKey]);
|
||||
const { types, limit, minQuery, debounceMs } = stableOptions;
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user