Fix WorldMap crash when path is undefined during early render

react-simple-maps types declare path as always non-null, but it is
undefined during the initial render before the MapProvider context
has fully initialised. Guard with an early return after all hooks
have been called, casting through unknown to reflect the true runtime
type without triggering the @typescript-eslint/no-unnecessary-condition
rule.
This commit is contained in:
2026-03-01 20:27:50 +01:00
parent 36e1e12a8a
commit f06fea699f

View File

@@ -83,6 +83,12 @@ function GeoLayer({
[selectedCountry, onSelectCountry],
);
// react-simple-maps types declare `path` as always defined, but it is
// undefined during early renders before the MapProvider context initialises.
// Cast through unknown to reflect the true runtime type and guard safely.
const safePath = path as unknown as typeof path | null;
if (safePath == null) return <></>;
return (
<>
{(geographies as { rsmKey: string; id: string | number }[]).map(