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

[Bug] Popup triggers immediately onClose event + after close popup it will not open again #1825

Closed
mrajaeim opened this issue Apr 8, 2022 · 9 comments
Assignees
Labels

Comments

@mrajaeim
Copy link

mrajaeim commented Apr 8, 2022

Description

Popup triggers immediately onClose event and after close popup, it will not open again
For the second problem, I think it's better to add a visibility prop for the popup to control its visibility in the parent component.

Expected Behavior

No response

Steps to Reproduce

1- first add your token to the below sandbox
2- click on the pin image
3- watch console logs (close event trigger on opening)
4- try close and reopen popup
sandbox code

Environment

  • Framework version: react-map-gl@7.0.10
  • Map library: mapbox-gl@2.8.0
  • Browser: Chrome 100.0
  • OS: windows 10
  • Reactjs: react@18.0.0
  • nextjs: next@12.1.4

Logs

No response

@mrajaeim mrajaeim added the bug label Apr 8, 2022
@Pessimistress
Copy link
Collaborator

This has to do with the use of <StrictMode> (which mounts the component twice). I think the correct behavior is to not trigger onClose when the popup is closed by unmounting.

@Pessimistress Pessimistress self-assigned this Apr 9, 2022
@mrajaeim
Copy link
Author

mrajaeim commented Apr 9, 2022

StrictMode

Thanks.
Also, I notice that the onClose event will not be removed from dom and it causes a bug that we cant update state in onClose;
for example:

onClose={() => {
     setPopup(false)
     console.log("hello")
 }}

every time I click the map or move it close event will trigger and if I try to open new popup, multiple close event will be generated.
I think the popup components needs a prop to rewrite close function

@Pessimistress
Copy link
Collaborator

That sounds like mapbox/mapbox-gl-js#11535

@Steve2724214
Copy link

This has to do with the use of <StrictMode> (which mounts the component twice). I think the correct behavior is to not trigger onClose when the popup is closed by unmounting.

I'm not using strict mode and am experiencing the same issue. Is there a work around while we wait for the fix?

@Pessimistress
Copy link
Collaborator

@HawaiianBBQ You are not experiencing the same issue. Please create a Code Sandbox.

@Pessimistress
Copy link
Collaborator

@mrajaeim After some consideration I do not think we should change how onClose works. With StrictMode, the open event will be fired twice and that is expected. close events should function symmetrically.

@Pessimistress
Copy link
Collaborator

This should be fixed in 7.0.11.

@apetta
Copy link

apetta commented Jul 3, 2022

I'm getting this issue in 7.0.16 with strict mode off on react 18.1.0.

The popup will not open when triggered, and if an onClose handler is set, then it fires immediately after the popup is triggered. Setting closeOnClick={false} makes everything work as expected however.

@Pessimistress
Copy link
Collaborator

@apetta Your issue is not related to this one. See #1847

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

No branches or pull requests

4 participants