wrolpi/app/src/components/calculators
Roland a74e4c6fc4
fix: break the import cycle that put useCalculators in the TDZ
The dashboard threw on arrival from any other page:

    ReferenceError: Cannot access 'useCalculators' before initialization
        at Module.useCalculators
        at DashboardCalculators

`Calculators.js` exports `useCalculators` as a `const` and imports the ten
calculators it renders.  Five of those reached back up to `Apps.js` for
`ColoredInput`, and `Apps.js` imports `CalculatorsPage` from
`Calculators.js` -- so the hub was in a cycle with its own leaves:

    Calculators.js -> calculators/ElectricalCalculators.js
                   -> Apps.js -> Calculators.js

Webpack compiles a `const` export to a live getter, and a getter read
before the module body reaches the declaration THROWS rather than
returning undefined.  That is the whole mechanism behind this particular
error, and it names the const it could not reach.

`ColoredInput` is a text field with a Label welded to one edge -- the
calculators' unit markers.  It has no business in the module that ROUTES
to the calculators, so it moved to `components/ui/Inputs.tsx`.  Nothing in
`components/ui` imports from `components/`, so a control kept there cannot
close a loop like this again.  Gallery entry added, per the standing rule.

`src/import-cycles.test.js` is the guard: a small import-graph walker,
scoped to hubs that export a `const` into their own subtree.  It fails
with the cycle printed, and it self-checks against a known cycle so it
cannot pass by finding nothing.  Verified red with the cycle planted back.

HONEST LIMIT: the guard is static because I could not reproduce the
RUNTIME error in a test.  TDZ needs a module to be mid-evaluation when the
getter is read, and by the time any spec body runs every module has
finished; babel also papers over it, handing back undefined where webpack
throws.  I tried an e2e that navigates to the dashboard and collects
window errors -- it passes with the cycle present, so it would have been a
test that cannot fail for the reason it claims, and I deleted it rather
than ship it.  A react-refresh trigger did not reproduce it either.  What
is checkable, and what is genuinely the defect, is the cycle.

1080 jest / 60 suites, 158 in ui-layout.cy.js, clean build.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 18:05:47 -06:00
..
DriveCalculator.js fix: break the import cycle that put useCalculators in the TDZ 2026-08-08 18:05:47 -06:00
DriveCalculator.test.js Add Drive Ratio calculator (pulleys, gears, sprockets) 2026-05-28 15:17:50 -06:00
ElectricalCalculators.js fix: break the import cycle that put useCalculators in the TDZ 2026-08-08 18:05:47 -06:00
ElectricalCalculators.test.js Calculators: add 4-Wire Kelvin segment to the Electrical Calculator. 2026-07-09 15:27:34 -06:00
FoodStorageCalculator.js fix: break the import cycle that put useCalculators in the TDZ 2026-08-08 18:05:47 -06:00
FoodStorageCalculator.test.js Rebuild Inventory as a config-only system with food catalog and calculators 2026-06-14 17:14:54 -06:00
HamCalculators.js fix: break the import cycle that put useCalculators in the TDZ 2026-08-08 18:05:47 -06:00
HamCalculators.test.js Antenna calculator: extract pure math, fix bugs, add tests. 2026-07-15 19:57:48 -06:00
mathConfig.js Adding more dashboard unit examples. Adding tests for unit conversion. 2026-04-04 17:56:08 -06:00
mathConfig.test.js Adding more dashboard unit examples. Adding tests for unit conversion. 2026-04-04 17:56:08 -06:00
OneTimePadCalculator.js ui: thirty-five files off Semantic, leaving fifteen 2026-08-08 18:04:01 -06:00
OneTimePadCalculator.test.js Moving OTP and Vin decoder to calculators to save Navbar space. Reworking calculators to purpose groups, and adding colors. 2026-07-01 18:48:06 -06:00
QRCodeCalculator.js ui: nine leaf files off Semantic, and the components they needed 2026-08-08 18:04:00 -06:00
RatioCalculator.js ui: thirty-five files off Semantic, leaving fifteen 2026-08-08 18:04:01 -06:00
RatioCalculator.test.js Adding quart to ratio calculator. Adding tests. 2025-12-25 18:45:32 -07:00
RationCalculator.js fix: break the import cycle that put useCalculators in the TDZ 2026-08-08 18:05:47 -06:00
RationCalculator.test.js ui: thirty-five files off Semantic, leaving fifteen 2026-08-08 18:04:01 -06:00
TemperatureCalculator.js ui: nine leaf files off Semantic, and the components they needed 2026-08-08 18:04:00 -06:00
VinDecoderCalculator.js ui: nine leaf files off Semantic, and the components they needed 2026-08-08 18:04:00 -06:00
VinDecoderCalculator.test.js Moving OTP and Vin decoder to calculators to save Navbar space. Reworking calculators to purpose groups, and adding colors. 2026-07-01 18:48:06 -06:00
WaterCalculator.js ui: thirty-five files off Semantic, leaving fifteen 2026-08-08 18:04:01 -06:00
WaterCalculator.test.js Adding realistic lifecycle test. 2026-05-28 18:06:48 -06:00