-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathapply-hooks-fixes.js
More file actions
112 lines (109 loc) · 3.54 KB
/
apply-hooks-fixes.js
File metadata and controls
112 lines (109 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import fs from 'fs';
import path from 'path';
const fixes = [
{
file: 'src/hooks/useAdvancedForms.tsx',
replacements: [
{
search: ` useEffect(() => {
stateManager.initializeDependencies(config.fields, config.conditionalLogic || []);
}, [config, stateManager]);`,
replace: ` useEffect(() => {
stateManager.initializeDependencies(config.fields, config.conditionalLogic || []);
}, [config.fields, config.conditionalLogic, stateManager]);`,
},
{
search: ` return () => subscription.unsubscribe();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stateManager, validateOnChange, autoSave, formId, onFieldChange]);`,
replace: ` return () => subscription.unsubscribe();
}, [stateManager, validateOnChange, autoSave, formId, onFieldChange, autoSaveManager]);`,
},
{
search: ` return () => {
subscription.unsubscribe();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autoSave, autoSaveInterval, formId]);`,
replace: ` return () => {
subscription.unsubscribe();
};
}, [autoSave, autoSaveInterval, formId, autoSaveManager, loadDraft]);`,
},
{
search: ` } finally {
setIsSubmitting(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stateManager, validateForm, onSubmit, formState.values, autoSave]);`,
replace: ` } finally {
setIsSubmitting(false);
}
}, [stateManager, validateForm, onSubmit, formState.values, autoSave, clearDraft]);`,
},
],
},
{
file: 'src/hooks/useAdvancedSearch.tsx',
replacements: [
{
search: ` useEffect(() => {
if (typeof window !== 'undefined') {
const storedHistory = JSON.parse(
localStorage.getItem('search_history_terms') || '[]',
) as string[];
setHistory(storedHistory);
}
}, [setHistory]);`,
replace: ` useEffect(() => {
if (typeof window !== 'undefined') {
const storedHistory = JSON.parse(
localStorage.getItem('search_history_terms') || '[]',
) as string[];
setHistory(storedHistory);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Run only once on mount`,
},
],
},
{
file: 'src/hooks/useInternationalization.tsx',
replacements: [
{
search: ` useEffect(() => {
const savedLanguage = localStorage.getItem('i18n:language') as LanguageCode | null;
if (savedLanguage && savedLanguage !== language) {
setLanguage(savedLanguage);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);`,
replace: ` useEffect(() => {
const savedLanguage = localStorage.getItem('i18n:language') as LanguageCode | null;
if (savedLanguage && savedLanguage !== language) {
setLanguage(savedLanguage);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Intentionally run once on mount`,
},
],
},
{
file: 'src/hooks/useSearchFilters.tsx',
replacements: [
{
search: ` }, [filters, pathname, router]);`,
replace: ` }, [filters, pathname, router]); // searchParams intentionally excluded - only used for initial state`,
},
],
},
];
fixes.forEach(({ file, replacements }) => {
let content = fs.readFileSync(file, 'utf8');
replacements.forEach(({ search, replace }) => {
content = content.replace(search, replace);
});
fs.writeFileSync(file, content, 'utf8');
console.log(`✅ Fixed: ${file}`);
});
console.log('\n🎉 All fixes applied!');