rmariuzzo / react-new-window

🔲 Pop new windows in React, using `window.open`.
https://rmariuzzo.github.io/react-new-window/
MIT License
442 stars 107 forks source link

onUnload function not working properly #130

Open AdityaKirad opened 1 year ago

AdityaKirad commented 1 year ago

the onUnload function triggers as soon as the new window opens up so the problem is that I have this state

const [popup, setPopUp] = useState(false);

and this button

<Button onClick={() => setPopUp(true)}>Login</Button>
{ popup && !session ? (
                <NewWindow url='/SignInPage' onUnload={() => setPopUp(false)} />
              ) : null }

so as I click on the button the state of popup become true and the new window pops up but since the onUnload function triggers before new window unload so the state of popup become false immediately and the popup closes but when I removed onUnload={() => setPopUp(false)} and clicked on the button the new window opens up and the it doesn't closes the onUnload function should triggered after the new window unload

nmathew98 commented 1 year ago

@rmariuzzo can i be assigned to this?

rmariuzzo commented 1 year ago

Yes

AdityaKirad commented 1 year ago

Yes

Hey @rmariuzzo can I also join this project

ilhamgum commented 1 year ago

you could use onLoad method and watch the closed value by interval created by @ilhantekir https://github.com/rmariuzzo/react-new-window/issues/109#issuecomment-1009683557

rmariuzzo commented 1 year ago

Checking on this issue I have noticed that the popup seems to open twice which trigger the unload function.

Looking at this closely, it seems the first popup tried to open but failed for some reason (extension, security, ???), then it retries and it opens.

I think this will need to be documented or addressed with more coverage.

rmariuzzo commented 1 year ago

It is worth mentioning that happened to me in Chrome with a few extensions and in Chrome using incognito mode.

rmariuzzo commented 1 year ago

Checking a little more deeper, the popup opening twice seems to be related on how the component renders. To me it looks like the component is rendering twice, this is not good. Will continue to triage other tickets to see if other issues are related to this.

Thanks all for your patience.

rmariuzzo commented 1 year ago

The previous issues was because I was on React 18 and it was fixed by: https://github.com/rmariuzzo/react-new-window/pull/134

rmariuzzo commented 1 year ago

@AdityaKirad which browser and React version are you using?