mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Projection Change Leaves Old Projection Visible in Dev Mode (Next.js v14)

Open TheodoreRed opened this issue 1 year ago • 2 comments

Framework: Next.js v14

I'm experiencing an issue with one of my maps in a React project using Mapbox GL JS. When I change the map's projection in development mode, the new projection is applied, but the previous projection remain visible in the background. However, after building the project, and running the build the problem disappears.

Has anyone encountered this behavior or have suggestions on how to diagnose and fix the issue in development mode?

TheodoreRed avatar Feb 04 '25 13:02 TheodoreRed

Hey, @TheodoreRed! Thank you for the report!

Could you provide a minimal example of what you see? What library do you use for wrapping Mapbox GL JS in React? It seems to me that it was caused not by GL JS, but by your setup logic or environment. I can only guess that it might be related to something like double rerendering of <StrictMode> as an example

underoot avatar Feb 05 '25 09:02 underoot

Hey @underoot I was able to resolve the double initialization in Strict Mode issue. Here's the snippet that worked for me:

[email protected]

const initializedRef = useRef(false);

useEffect(() => {
  if (initializedRef.current) return;
  initializedRef.current = true;

  // Initialize map

}, []);

TheodoreRed avatar Feb 06 '25 13:02 TheodoreRed