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

Unmounting <Image /> throws an error #727

Closed
Hless opened this issue May 8, 2019 · 1 comment
Closed

Unmounting <Image /> throws an error #727

Hless opened this issue May 8, 2019 · 1 comment

Comments

@Hless
Copy link
Contributor

Hless commented May 8, 2019

Current behaviour

Unmounting an <Image /> component produces the following error:

mapbox-gl.js:23344 Uncaught TypeError: Cannot read property 'removeImage' of undefined
    at r.removeImage (mapbox-gl.js:23344)
    at Function.Image.removeImage (image.js:96)
    at Image.componentWillUnmount (image.js:42)
    ... 

Expected behaviour

Be able to unmount an Image component without errors.

Possible solution

Also check for undefined style in when unmounting the Image component:
if (map && getStyle()) {

See:

private static removeImage(props: Props) {
const { id, map } = props;
if (map) {
map.removeImage(id);
}
}

Code to reproduce

<Map style="STYLE_UR"}>
    <Image id="image-marker" url="/url/to/image.png" />
    <Layer id="layer" layout={{"icon-image": "image-marker", 'icon-allow-overlap': true  }}>
         <Feature coordinates={COORDINATES} draggable={true} />
     </Layer>
</Map>

Environment

"mapbox-gl": "^0.53.1"
"react-mapbox-gl": "^4.3.0",

Note: Also tried with mapbox-gl ^0.54.0

@mklopets
Copy link
Collaborator

Released your fix as v4.5.1. Thanks a bunch!

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