Skip to content

Persistent iframe - #23

Draft
rusty-key wants to merge 7 commits into
melange-v3from
persistent-iframe
Draft

Persistent iframe#23
rusty-key wants to merge 7 commits into
melange-v3from
persistent-iframe

Conversation

@rusty-key

Copy link
Copy Markdown
Collaborator

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

@rusty-key
rusty-key requested a review from denis-ok March 26, 2024 16:59

@rusty-key rusty-key left a comment

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread src/ReshowcaseUi.re
| None => React.null
| Some(body) => ReactDOM.createPortal(children, body)
}}
</iframe>

Copy link
Copy Markdown
Collaborator Author

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

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread src/ReshowcaseUi.re
Comment on lines +1090 to +1091
| Some(window) when !showRightSidebar =>
Window.postMessage(window, RightSidebarDisplayed)

Copy link
Copy Markdown
Collaborator Author

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

Comment thread src/ReshowcaseUi.re
<div name="DemoUnit" style=Styles.container>
<div style=Styles.contents> {demoUnit(props)} </div>
{switch (parentWindowRightSidebarElem) {
{switch (sidebarElem) {

Copy link
Copy Markdown
Collaborator Author

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.

@rusty-key
rusty-key marked this pull request as ready for review March 26, 2024 19:38
@rusty-key

Copy link
Copy Markdown
Collaborator Author

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.

@rusty-key

Copy link
Copy Markdown
Collaborator Author

oh well, there is an issue with incorrect mounting of styles/scripts. They get mounted to parent root instead of iframe :/
Investigating

@rusty-key
rusty-key marked this pull request as draft March 27, 2024 14:59

@jchavarri jchavarri left a comment

Copy link
Copy Markdown
Member

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).

Comment thread src/ReshowcaseUi.re
Comment on lines -912 to -914
let useFullframeUrl: bool = [%mel.raw
{js|typeof USE_FULL_IFRAME_URL === "boolean" ? USE_FULL_IFRAME_URL : false|js}
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this feature removed?

Copy link
Copy Markdown
Collaborator Author

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

Comment thread src/ReshowcaseUi.re
| None => React.null
| Some(body) => ReactDOM.createPortal(children, body)
}}
</iframe>

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants