I am attempting to assist with what was spoken about in issue #48326 preview external window disappears. The goal is if the user chose to have a preview window open it should not disappear, nor should a new window open when advancing in the curriculum, but rather the same window should stay open and refresh with the data from the next challenge. additionally, as mentioned in the comments, I will close the window on leaving the challenges.
I am trying to implement the advise given in the issue but I think I am having difficulty in the saga.
on page load I get:
react-dom.development.js:237 Uncaught RangeError: Maximum call stack size exceeded.
at Object.invokeGuardedCallbackDev
and when I try to open the preview:
TypeError: Cannot read properties of undefined (reading 'createElement')
I guess it is because it was expecting a document but now it is recieving a window:
line 90 in previewPortal: this.props.storeportalWindow(this.externalWindow);
Please advise what is causing these two errors and how I can go about fixing them? Thank you.
Summary:
Keep the same functionality as currently exists. Only, on advancing and moving backwards in the curriculum, if the portalWindow is open, keep it open and populate it with the new content. If going to another page non related to challenges (settings for example), close the portal window.
Please confirm that the advise given in the issue is correct :
I would also like to convert the portal-preview into a functional component but it is throwing many console errors and the window is not being filled with the props.children:
That does sound like a decent plan of action. The main issue is ensuring the window closes when it should. Should the external window close if I navigate to /learn?
If you do this, be sure to do it in a separate PR.
My understanding is that line of code is necessary to prevent cases where the Camper navigates away from the current page, and the external window remains open. That is, before the main Window is disposed, ensure the external Window is closed.
it works as desired when you advance in the curriculum. however press the open and close modal control button a few times and you will see the extra windows being created.
The only thing I can think of is to have the window close from a different component (not the preview portal)
update: I just moved it into desktop layout, its working as expected.
that is the last thing left to do to close the issue
edit: ok I think ive solved for it,
i removed that condition with the main window because I never saw it triggered and I dont think it was actually doing anything. I will make pull request.