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

Renders black screen after multiple renders. #1007

Open
MarkLyck opened this issue Jun 2, 2022 · 1 comment
Open

Renders black screen after multiple renders. #1007

MarkLyck opened this issue Jun 2, 2022 · 1 comment

Comments

@MarkLyck
Copy link

MarkLyck commented Jun 2, 2022

I have an application that can display 2 maps on the same page.

The first map always loads without any issues (mostly).

However when you open a popup with a second map, it works the first time you open one, but if you close it and open it again it displays a back screen instead.

Works the first time
Screen Shot 2022-06-02 at 13 10 47

Always breaks the second time and any time after that.
Screen Shot 2022-06-02 at 13 09 30

I can't see that I'm doing anything wrong with my setup or rendering? I also checked why-did-you-render and I have no unnecesarry re-renders happening on this component.

import * as mapboxgl from 'mapbox-gl'
import ReactMapboxGl, { ZoomControl, Cluster, Marker } from 'react-mapbox-gl'

Object.getOwnPropertyDescriptor(mapboxgl, 'accessToken')?.set(
  'MY_TOKEN'
)
const MapBox = ReactMapboxGl({
  scrollZoom: false,
})

const BROWSER_HAS_WEBGL = !!window.WebGLRenderingContext

export const MapView = ({
  data = [],
  onMarkerClick = () => {},
  isLoading,
  hasZoom = true,
  defaultZoom = 3,
  defaultBounds,
  width,
  TooltipContent,
}: MapProps) => {
  const theme = useTheme()
  const [hasMapMounted, setMapMounted] = useState(false)
  const [bounds, setBounds] = useState<undefined | BoundsType>(defaultBounds)
  const [zoom] = useSessionStorageState<[number]>('zoom', {
    defaultValue: [defaultZoom],
  })

  const [center, setCenter] = useSessionStorageState<[number, number]>(
    'map-center',
    { defaultValue: [-106.3468, 56.1304] }
  )

  if (!APP_CONFIG.IS_MOCKED_ENV && BROWSER_HAS_WEBGL === false)
    return <WebGLError />

  return (
      <MapBox
        className="chromatic-ignore"
        style={`mapbox://styles/mapbox/${theme.type}-v10`}
        fitBoundsOptions={
          data.length ? { padding: 200, maxZoom: 16 } : undefined
        }
        fitBounds={bounds}
        center={center}
        containerStyle={{
          opacity: /* c8 ignore next */ hasMapMounted ? 1 : 0,
          height: '100%',
          width: '100%',
        }}
        trackResize={false}
        onStyleLoad={(map) => {
            map?.resize?.()
            setMapMounted(true)
          }
        }
        zoom={zoom}
      >
        <>
              <Cluster
                ClusterMarkerFactory={ClusterMarker}
                zoomOnClick={true}
                zoomOnClickPadding={80}
                radius={100}
              >
                {data.map((point: any) => (
                  <Marker
                    coordinates={[point.lon, point.lat]}
                    anchor="bottom"
                    key={point.id}
                  >
                    <MarkerItem
                      point={point}
                      renderPoint={onMarkerClick}
                      setCenter={setCenter}
                      selectedId={undefined}
                    />
                  </Marker>
                ))}
              </Cluster>
        </>
      </MapBox>
  )
}

Why am I getting a black screen?

Looking at the html the canvas does not render at all after a second component is rendered.

Versions:
"react-mapbox-gl": "5.1.1",
"mapbox-gl": "2.8.2",

@hasnain-GTS
Copy link

Any solution ?

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

2 participants