react-new-window icon indicating copy to clipboard operation
react-new-window copied to clipboard

onUnload function not working properly

Open AdityaKirad opened this issue 3 years ago • 9 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

AdityaKirad avatar Aug 31 '22 10:08 AdityaKirad

@rmariuzzo can i be assigned to this?

nmathew98 avatar Oct 16 '22 02:10 nmathew98

Yes

rmariuzzo avatar Oct 16 '22 04:10 rmariuzzo

Yes

Hey @rmariuzzo can I also join this project

AdityaKirad avatar Oct 16 '22 04:10 AdityaKirad

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

ilhamgum avatar Nov 22 '22 02:11 ilhamgum

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 avatar Nov 26 '22 15:11 rmariuzzo

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

rmariuzzo avatar Nov 26 '22 15:11 rmariuzzo

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 avatar Nov 26 '22 15:11 rmariuzzo

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 avatar Nov 26 '22 16:11 rmariuzzo

@AdityaKirad which browser and React version are you using?

rmariuzzo avatar Nov 26 '22 16:11 rmariuzzo