-
Notifications
You must be signed in to change notification settings - Fork 0
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
Persistent iframe #23
base: melange-v3
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about some unrelated formatting changes, looks like refmt defaults updated at some point 🤷♂️
Besides main refactor, I had to tweak right sidebar because it was throwing at runtime with my solution.
| None => React.null | ||
| Some(body) => ReactDOM.createPortal(children, body) | ||
}} | ||
</iframe> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core change. Instead of referencing iframe with demo, we just render demo using portal in persistent iframe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about how this change might affect stateful changes that the iframe keeps from one demo to another? E.g. if some iframe loads some styles in the page head
then they might "leak" from one demo to the next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I didn't. I assumed this is the responsibility of the consumer: do a cleanup on unmount.
| Some(window) when !showRightSidebar => | ||
Window.postMessage(window, RightSidebarDisplayed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why it's done via "signalling", but decided to keep it this way for now to limit the scope of this PR
@@ -867,7 +838,7 @@ module DemoUnit = { | |||
|
|||
<div name="DemoUnit" style=Styles.container> | |||
<div style=Styles.contents> {demoUnit(props)} </div> | |||
{switch (parentWindowRightSidebarElem) { | |||
{switch (sidebarElem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also refactored the sidebar to use reference instead of getting elements by id, which seems much more fragile and caused runtime exceptions for me.
I think it's ready for review. I am not sure why things are implemented via signalling instead of using callbacks, so I refactored relevant part and willing to refactor more in the future. But please let me know if I am missing something. |
oh well, there is an issue with incorrect mounting of styles/scripts. They get mounted to parent root instead of iframe :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how styles don't "leak" from one demo to the next (see inline comment).
let useFullframeUrl: bool = [%mel.raw | ||
{js|typeof USE_FULL_IFRAME_URL === "boolean" ? USE_FULL_IFRAME_URL : false|js} | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this feature removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad. I was not sure what it was doing and how to debug it. Will check
| None => React.null | ||
| Some(body) => ReactDOM.createPortal(children, body) | ||
}} | ||
</iframe> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about how this change might affect stateful changes that the iframe keeps from one demo to another? E.g. if some iframe loads some styles in the page head
then they might "leak" from one demo to the next.
Currently, reshowcase is reloading
iframe
every time we go from demo to demo. This causes fetching/parsing/executing all assets:https://github.com/ahrefs/reshowcase/assets/1197026/e6705a68-2cd9-4c3a-8ad6-4122e77e38e8
It makes reshowcase navigation unnecessarily slow, especially on large applications.
Instead, we can make iframe persistent, and only replace its content. This way, reshowcase will fetch assets only once and only need to render relevant demo on navigation:
https://github.com/ahrefs/reshowcase/assets/1197026/798529fc-44db-4bea-8018-87794116c829
This is not yet clean solution, just "showcase" of possibility. I'll continue working on it