rmariuzzo / react-new-window

🔲 Pop new windows in React, using `window.open`.

Home Page:https://rmariuzzo.github.io/react-new-window/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onUnload function not working properly

AdityaKirad opened this issue · comments

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

@rmariuzzo can i be assigned to this?

Yes

Hey @rmariuzzo can I also join this project

you could use onLoad method and watch the closed value by interval created by @ilhantekir
#109 (comment)

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.

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

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.

The previous issues was because I was on React 18 and it was fixed by: #134

@AdityaKirad which browser and React version are you using?