Commit fc00c46
FIX: Deduplicate getExplorer and getDbExplorer API calls via Zustand store (#71)
* fix: dedupe getExplorer API call via Zustand store
Both explorer-component.jsx and chat-ai/Body.jsx were independently
calling explorerSvc.getExplorer(projectId), causing a duplicate
GET /explorer request every time the chat drawer opened.
Introduce a minimal Zustand store (explorer-store.js) that holds the
shared response. explorer-component.jsx becomes the single writer
(updates on every successful fetch, clears on project switch), and
Body.jsx reads explorerData from the store to populate prompt
autocomplete instead of issuing its own fetch. getDbExplorer in
Body.jsx is unchanged.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: dedupe getDbExplorer API call via the same Zustand store
Extend useExplorerStore with a dbExplorerData slice so chat-ai/Body.jsx
stops fetching /db_explorer independently. Previously, opening the chat
drawer triggered a second identical GET /db_explorer alongside the one
already issued by explorer-component.jsx on mount.
explorer-component.jsx becomes the single writer for both slices
(getExplorer and getDbExplorer wrappers), and the existing project-switch
clear effect now resets both slices via an expanded clearExplorerData.
Body.jsx subscribes to the store and mirrors dbExplorerData into the
existing promptAutoComplete.dbData shape — no direct explorerService
usage remains in chat-ai/Body.jsx (explorerService import, useRef import,
and the explorerSvc ref were dropped).
Also updated the PR description to cover both refactors in one PR.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: address review feedback on explorer dedup refactor
Three review-driven tweaks from the first round of review on this branch:
- explorer-component.jsx: publish the raw /explorer response to
useExplorerStore (via rawTreeDataRef.current) before the in-place
mutations by sortModels, applyModelDecorations, and transformTree
begin. The store now matches its documented contract and Body.jsx's
autocomplete receives the untransformed children shape it did before
the dedup refactor.
- explorer-component.jsx: add clearExplorerData to the dependency array
of the project-switch clear effect. Zustand action refs are stable in
practice, so effect cadence is unchanged, but the deps array is now
exhaustive and future-proof against a non-stable refactor.
- Body.jsx: expand the short comment above the mirror effects into a
block that documents why this component is read-only and lists the
escape hatches (fetch fallback here or a loading state in InputPrompt)
to reach for if the "explorer mounts before chat drawer" invariant
ever breaks.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: use null-sentinel for schemaMenu to gate explorer fetch correctly
The prior `schemaMenu?.length` guard on the schema/schema-change useEffect
conflated "schemas not loaded yet" (schemaMenu === []) with "loaded but
empty" (same []). A reviewer correctly flagged that a project with no DB
connection would have the fetch silently suppressed.
Fix:
- Initialise schemaMenu as null (sentinel for "not yet loaded") instead of [].
- Revert the effect guard to `if (schemaMenu)` so it fires the moment
schemaMenu transitions from null to an array, regardless of whether that
array has items.
- Add null-safe guards — `(schemaMenu || [])` — at the JSX consumers
(`.map`, `.length` comparisons) that now need to handle the pre-load
null state. During loading, seed-related actions remain disabled and
the schema dropdown is empty, both the correct UX.
- Add an inline comment above the effect explaining the sentinel so this
design choice is visible at the call site.
Net result: the original optimisation (skip the redundant mount-time
fetch while schemaMenu is still []) is preserved, and the reviewer's
no-DB regression is fixed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: only clear explorer store on actual project change
The project-switch clear effect was also firing on initial mount (and
on any remount of explorer-component within the same session), which
briefly wiped valid store data and could leave chat autocomplete empty
until the next fetch resolved. Gate the clear with a prevProjectIdRef
so clearExplorerData() only fires when projectId actually changes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent bd06a62 commit fc00c46
3 files changed
Lines changed: 78 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | | - | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | 74 | | |
| 75 | + | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
205 | 213 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
220 | 221 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
236 | 228 | | |
237 | 229 | | |
238 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
176 | 177 | | |
177 | 178 | | |
178 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
179 | 187 | | |
180 | 188 | | |
181 | 189 | | |
| |||
194 | 202 | | |
195 | 203 | | |
196 | 204 | | |
197 | | - | |
| 205 | + | |
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
| |||
976 | 984 | | |
977 | 985 | | |
978 | 986 | | |
979 | | - | |
| 987 | + | |
980 | 988 | | |
981 | 989 | | |
982 | 990 | | |
| |||
1014 | 1022 | | |
1015 | 1023 | | |
1016 | 1024 | | |
1017 | | - | |
| 1025 | + | |
1018 | 1026 | | |
1019 | 1027 | | |
1020 | 1028 | | |
| |||
1035 | 1043 | | |
1036 | 1044 | | |
1037 | 1045 | | |
1038 | | - | |
| 1046 | + | |
1039 | 1047 | | |
1040 | 1048 | | |
1041 | 1049 | | |
| |||
1118 | 1126 | | |
1119 | 1127 | | |
1120 | 1128 | | |
1121 | | - | |
| 1129 | + | |
1122 | 1130 | | |
1123 | 1131 | | |
1124 | 1132 | | |
| |||
1127 | 1135 | | |
1128 | 1136 | | |
1129 | 1137 | | |
1130 | | - | |
| 1138 | + | |
1131 | 1139 | | |
1132 | 1140 | | |
1133 | 1141 | | |
| |||
1244 | 1252 | | |
1245 | 1253 | | |
1246 | 1254 | | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
1247 | 1259 | | |
1248 | 1260 | | |
1249 | 1261 | | |
1250 | 1262 | | |
1251 | 1263 | | |
1252 | 1264 | | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
1253 | 1277 | | |
1254 | 1278 | | |
1255 | 1279 | | |
| |||
1258 | 1282 | | |
1259 | 1283 | | |
1260 | 1284 | | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
1261 | 1288 | | |
1262 | 1289 | | |
1263 | 1290 | | |
| |||
1299 | 1326 | | |
1300 | 1327 | | |
1301 | 1328 | | |
| 1329 | + | |
1302 | 1330 | | |
1303 | 1331 | | |
1304 | 1332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments