Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suspending the MapViewContent component will crash the map with React 18 #61

Open
eatyourgreens opened this issue Jul 1, 2024 · 0 comments

Comments

@eatyourgreens
Copy link

const [viewState, setViewState] = useRecoilState(mapViewStateState);
useSyncMapUrl();
const background = useRecoilValue(backgroundState);
const showLabels = useRecoilValue(showLabelsState);
const { mapStyle, firstLabelId } = useBasemapStyle(background, showLabels);
const viewLayers = useRecoilValue(viewLayersState);
const viewLayersParams = useRecoilValue(viewLayersParamsState);
const interactionGroups = useRecoilValue(interactionGroupsState);
const fitBounds = useRecoilValue(mapFitBoundsState);
const resetFitBounds = useResetRecoilState(mapFitBoundsState);
useEffect(() => {
// reset map fit bounds whenever MapView is mounted
resetFitBounds();
}, [resetFitBounds]);

Heads up that the Recoil state here works fine with React 17, but crashes with the new createRoot(node).render() in React 18. Moving the Recoil state down into individual components fixes it. I think that the React Map GL Map component crashes if it renders while suspended, but only with the new concurrent rendering API.

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant