Skip to content

Commit 0ea140e

Browse files
committed
fix(admin): bypass admin/stats + shared barrels in server router
Follow-up to 'avoid ~/modules/shared barrel in server-only router': the first fix only changed the direct import, but adminStats.ts still went through the `~/modules/admin/stats` barrel for schemas + types. That barrel re-exports `ConformiteStatsPage` (client component), which in turn imports from `~/modules/shared` → `useZodForm` / `useDsfrModal` → the `react-server` build of `react-hook-form` that does not export `useForm` / `useRef`. The Next.js dev overlay kept surfacing the same error even though the build passed in CI (turbopack vs webpack difference). Switch every import in the router to internal file paths (`~/modules/admin/stats/{schemas,types}` and `~/modules/shared/nafSections`) and document the trade-off with a comment block. The proper long-term fix is to split each barrel into client / server halves.
1 parent bd4f59d commit 0ea140e

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

packages/app/src/server/api/routers/adminStats.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ import {
1010
sql,
1111
} from "drizzle-orm";
1212

13+
// Server-only router: every import below bypasses the `~/modules/admin/stats`
14+
// and `~/modules/shared` barrels and targets internal files instead. Those
15+
// barrels re-export React-only code (`ConformiteStatsPage`, `useZodForm`,
16+
// `useDsfrModal`) whose dependency chain ends in `react-hook-form`'s
17+
// `react-server.esm.mjs` build — which does not expose `useForm`. Indirect
18+
// imports from server code therefore fail at `next build` and the dev
19+
// server error overlay. Hitting files directly is ugly but correct until
20+
// the barrels get split into client/server halves.
21+
import {
22+
getCampaignProgressionSchema,
23+
getGapAlertRateSchema,
24+
getMultiYearGapTrendSchema,
25+
} from "~/modules/admin/stats/schemas";
1326
import type {
1427
CampaignProgressionPoint,
1528
CampaignProgressionSeries,
1629
GapAlertRateResult,
1730
MultiYearGapPoint,
1831
MultiYearGapTrendSeries,
19-
} from "~/modules/admin/stats";
20-
import {
21-
getCampaignProgressionSchema,
22-
getGapAlertRateSchema,
23-
getMultiYearGapTrendSchema,
24-
} from "~/modules/admin/stats";
32+
} from "~/modules/admin/stats/types";
2533
import { COMPANY_SIZE_RANGES } from "~/modules/domain";
26-
// Server-only router: import the constants directly from the internal file
27-
// instead of the `~/modules/shared` barrel, which also re-exports the
28-
// `useZodForm` client hook. The barrel pulls `react-hook-form`, and its
29-
// server build (`react-server.esm.mjs`) does not export `useForm`, so
30-
// indirect imports from server code break `next build`.
3134
import {
3235
DOMINANT_NAF_SECTIONS,
3336
OTHER_NAF_SEGMENT,

0 commit comments

Comments
 (0)