Skip to content

Commit 1170897

Browse files
committed
chore: mitigate not rendering with delay
1 parent c73025b commit 1170897

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/pluggableWidgets/maps-web/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
### Fixed
1010

11+
- We mitigated the issue with Maps widgets not rendering in some cases.
12+
1113
- We fixed an issue where GoogleMap and LeafletMap uses array index for the list item which causes issues when filtering large amounts of locations. Thanks to @jeroen-huizer-conclusion for the contribution.
1214

1315
- We fixed an issue where where browser console throw warning of unknown listener when the location has title in LeafletMap. Thanks to @jeroen-huizer-conclusion for the contribution.
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1-
import { ReactElement } from "react";
1+
import { PropsWithChildren, ReactElement, ReactNode, useEffect, useState } from "react";
22
import { GoogleMapContainer, GoogleMapsProps } from "./GoogleMap";
33
import { LeafletMap, LeafletProps } from "./LeafletMap";
44

55
interface SwitcherProps extends GoogleMapsProps, LeafletProps {}
66

77
export const MapSwitcher = (props: SwitcherProps): ReactElement => {
8-
return props.mapProvider === "googleMaps" ? <GoogleMapContainer {...props} /> : <LeafletMap {...props} />;
8+
return props.mapProvider === "googleMaps" ? (
9+
<GoogleMapContainer {...props} />
10+
) : (
11+
<Delayed delay={1000}>
12+
<LeafletMap {...props} />
13+
</Delayed>
14+
);
15+
};
16+
17+
type DelayedProps = {
18+
delay: number;
19+
} & PropsWithChildren;
20+
21+
const Delayed = ({ children, delay }: DelayedProps): ReactNode => {
22+
const [isVisible, setIsVisible] = useState(false);
23+
24+
useEffect(() => {
25+
const timeout = setTimeout(() => {
26+
setIsVisible(true);
27+
}, delay);
28+
return () => clearTimeout(timeout);
29+
}, [delay]);
30+
31+
return isVisible ? children : null;
932
};

0 commit comments

Comments
 (0)