Commit 60fa5c7
fix(lotw): stop /lotw page from refetching in an infinite loop (#208)
The /lotw page hammered /api/stations, /api/lotw/upload, and
/api/lotw/download continuously because of a triple-cycle dependency
tangle:
1. useEffect deps include `loading` and `loadData`
2. loadData calls setLoading(true) on entry, setLoading(false) on
finish — flipping `loading` each call retriggers useEffect
3. loadData's useCallback deps include `selectedStation`, and
loadData calls setSelectedStation(...) to pick a default — the
state change reissues loadData's identity, which is also a dep
of useEffect
Each of #1 or #2/#3 alone is enough to loop. Combined, the page
re-rendered constantly and hit three API endpoints on each pass.
Fix:
- loadData useCallback deps = [] (no longer a function of selectedStation)
- setSelectedStation uses a functional updater so it can derive the
default from the freshly-fetched stations without depending on
selectedStation in deps
- useEffect waits on UserContext's `loading` (not this component's),
so the auth gate doesn't redirect during the initial /api/user check
Net: page mounts → one fetch round → idle. Manual refresh button and
post-action reloads still call loadData explicitly.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 08f96e8 commit 60fa5c7
1 file changed
Lines changed: 21 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
76 | | - | |
77 | | - | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
88 | 93 | | |
89 | 94 | | |
90 | | - | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
97 | | - | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
103 | | - | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
110 | | - | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
118 | | - | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
| |||
0 commit comments