9494## Critical Bug Prevention Patterns
9595
9696### Memory Management
97+
9798- ** ALWAYS** dispose Monaco Editor instances: ` return () => editor.dispose(); ` in useEffect
9899- ** NEVER** allow memory leaks in long-running components
99100- Clear timeouts and intervals in cleanup functions
100101
101102### React Performance (MANDATORY)
103+
102104- ** ALWAYS** use ` useMemo ` for expensive computations and object/array creation
103105- ** ALWAYS** use ` useCallback ` for functions passed to dependencies
104106- ** ALWAYS** memoize table columns, filtered data, and computed values
@@ -107,18 +109,19 @@ src/
107109
108110``` typescript
109111// ✅ REQUIRED patterns
110- const displaySegments = useMemo (() =>
111- segments .filter (segment => segment .visible ), [segments ]
112- );
112+ const displaySegments = useMemo (() => segments .filter ((segment ) => segment .visible ), [segments ]);
113113const handleClick = useCallback (() => {
114114 // logic
115115}, [dependency ]);
116116
117117// ✅ PREFER direct callbacks over useEffect
118- const handleInputChange = useCallback ((value : string ) => {
119- setSearchTerm (value );
120- onSearchChange ?.(value );
121- }, [onSearchChange ]);
118+ const handleInputChange = useCallback (
119+ (value : string ) => {
120+ setSearchTerm (value );
121+ onSearchChange ?.(value );
122+ },
123+ [onSearchChange ],
124+ );
122125
123126// ❌ AVOID unnecessary useEffect
124127// useEffect(() => {
@@ -127,11 +130,13 @@ const handleInputChange = useCallback((value: string) => {
127130```
128131
129132### Display Safety
133+
130134- ** ALWAYS** provide fallback values: ` Number(value) || 0 `
131135- ** NEVER** allow division by zero: ` capacity > 0 ? value/capacity : 0 `
132136- ** ALWAYS** handle null/undefined data gracefully
133137
134138### Security & Input Validation
139+
135140- ** NEVER** expose authentication tokens in logs or console output
136141- ** ALWAYS** validate user input before processing
137142- ** NEVER** skip error handling for async operations
@@ -271,19 +276,17 @@ Uses React Router v5 hooks (`useHistory`, `useParams`, etc.). Always validate ro
271276
272277``` typescript
273278// ✅ PREFERRED pattern for URL parameters
274- const sortColumnSchema = z
275- .enum ([' column1' , ' column2' , ' column3' ])
276- .catch (' column1' );
279+ const sortColumnSchema = z .enum ([' column1' , ' column2' , ' column3' ]).catch (' column1' );
277280
278281const SortOrderParam: QueryParamConfig <SortOrder []> = {
279- encode : (value ) => value ? encodeURIComponent (JSON .stringify (value )) : undefined ,
280- decode : (value ) => {
281- try {
282- return value ? JSON .parse (decodeURIComponent (value )) : [];
283- } catch {
284- return [];
285- }
286- },
282+ encode : (value ) => ( value ? encodeURIComponent (JSON .stringify (value )) : undefined ) ,
283+ decode : (value ) => {
284+ try {
285+ return value ? JSON .parse (decodeURIComponent (value )) : [];
286+ } catch {
287+ return [];
288+ }
289+ },
287290};
288291
289292const [urlParam, setUrlParam] = useQueryParam (' sort' , SortOrderParam );
0 commit comments