Skip to content
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

Fix memory leaks #102

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Fix memory leaks #102

wants to merge 8 commits into from

Conversation

jculvey
Copy link
Contributor

@jculvey jculvey commented Jan 26, 2023

Addresses the memory leak issue we found in the reframed demo

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

Lgtm once the review feedback is addressed! Thank you James.

@@ -26,6 +26,8 @@ export function Header({
}`}
placeholder="What needs to be done?"
autoFocus
autoComplete="off"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that this attribute makes no difference. Can you please confirm and remove?

@@ -26,6 +26,8 @@ export function Header({
}`}
placeholder="What needs to be done?"
autoFocus
autoComplete="off"
spellCheck={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment with a reference to the chrome big we filed? Thanks

@@ -60,6 +60,7 @@ export class GenericMessageBus implements MessageBus {
}

dispatch(eventName: string, value: JSONValue) {
value = JSON.parse(JSON.stringify(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment to explain what's going on here?

Also could we use https://developer.mozilla.org/en-US/docs/Web/API/structuredClone instead? (structuredClone feels less hacky)

@@ -80,7 +80,28 @@ export class PiercingFragmentOutlet extends HTMLElement {

disconnectedCallback() {
if (this.fragmentHost) {
unmountedFragmentIds.add(this.fragmentHost.fragmentId);
const fragmentId = this.fragmentHost.fragmentId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment before this block explaining what we are doing here? Thanks

<piercing-fragment-host fragment-id=${fragmentConfig.fragmentId}>
</piercing-fragment-host>
${prePiercingStyles}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh... I see. This explains the FOUC

@@ -463,6 +466,35 @@ function getEscapedReframedClientCode(fragmentId: string) {
</script>`;
}

function getEmbeddedStyleScript(fragmentId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please document the purpose of this fn. thank you

// monkey patch global addEventListner on window and document so that we can automatically unregister
// any listeners created from within a registered fragment.
const addEventListenerTargets = [window, document];
// const addEventListenerTargets = [Node.prototype];
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

if (listenerFns) {
listenerFns.push({
target: addEventListenerTarget,
// target: this,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove


return originalDocumentAddEventListener.call(
addEventListenerTarget,
// this,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

@@ -368,6 +368,7 @@ export class PiercingGateway<Env> {
<piercing-fragment-host fragment-id=${fragmentConfig.fragmentId}>
${prePiercingStyles}
--FRAGMENT_CONTENT--
<div class="fragment-end"></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting.. this works, but it really shouldn't be part of the library. Is there a way to avoid it?

If not can you please add a comment here explaining that the end marker is only used by the seams visualization in this demo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can use body.show-seams piercing-fragment-host:has(*) instead. Dario mentioned a corner case where the fragment host contains non-visible elements (which would still cause the seams to display). I can't repro that with the productivity suite, but it can definitely happen.

I can't really think of an alternative to the above selector that wouldn't involve embedding a sentinel value element that we then query for with a more specific selector. Open to ideas.

Personally, I vote to go with body.show-seams piercing-fragment-host:has(*) for now since it makes the demo code simpler unless we can find a use case within the productivity suite which breaks things.

@@ -380,6 +381,7 @@ export class PiercingGateway<Env> {
<iframe id="iframe_${fragmentId}" style="display: none" srcdoc="
<body>
--FRAGMENT_CONTENT--
<div class="fragment-end"></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

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