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

chore(ami): drop unused assets, save new snippets #421

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

Conversation

wesleyboar
Copy link
Member

@wesleyboar wesleyboar commented Feb 5, 2025

Overview & Changes

  • Remove unused assets.
  • Save new snippets.

Related

Testing & UI

N/A

Notes

These iframe-… snippets deserve to become a new TACC/Core-CMS template.

@wesleyboar wesleyboar marked this pull request as ready for review February 5, 2025 22:07
@wesleyboar wesleyboar requested a review from taoteg February 5, 2025 22:07
Copy link
Collaborator

@taoteg taoteg left a comment

Choose a reason for hiding this comment

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

Excellent! I added a comment butt leave it up to you if you wanna add it in.

iframe.addEventListener('load', () => setupResizeObserver(iframe));
}
window.addEventListener('resize', () => debouncedResizeIframe(iframe));
</script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I ended up adding this line as well, because the iframe content can take a few seconds to populate and kept getting inconsistent resizing behavior, often having to trigger a resize event to get the redraw to take. This seems to properly trigger it without having to touch anything.

window.addEventListener('load', () => window.dispatchEvent(new Event('resize')));

Note: There are still some load time issues from the upstream end, right now it can be up to 6 seconds before the iframe fully 'loads'.

Copy link
Member Author

@wesleyboar wesleyboar Feb 5, 2025

Choose a reason for hiding this comment

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

Okay. Doesn't hurt, but I think we're still fighting race condition, cuz iFrame content (not part of this window) can load after window load.

I think what we really need is the iFrame content (i.e. every app) to dispatch that event to it's parent doc when it actually "loads".

Copy link
Member Author

@wesleyboar wesleyboar Feb 6, 2025

Choose a reason for hiding this comment

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

Or a custom event to which we also listen. Google says window.parent.dispatchEvent(ourEvent);. And it seems simple to create a custom event.

@taoteg
Copy link
Collaborator

taoteg commented Feb 6, 2025

Following up here...

I requested the following code be added to the upstream iframe generated by the Dash app:

// Inside the iframe

// Init Event.
function dispatchCustomIFrameInitEventToParent() {
    const event = new CustomEvent('IFrameInit', {
        detail: { message: 'initializing iframe' }, // optional
        bubbles: true, // Allow the event to bubble up
        cancelable: true // Allow the event to be canceled if needed
    });

    // Dispatch the event to the parent window
    window.parent.dispatchEvent(event);
}

// Trigger the event.
dispatchCustomIFrameInitEventToParent();

// Loaded Event.
function dispatchCustomIFrameLoadedEventToParent() {
    const event = new CustomEvent('IFrameLoaded', {
        detail: { message: 'Iframe loaded' }, // optional
        bubbles: true, // Allow the event to bubble up
        cancelable: true // Allow the event to be canceled if needed
    });

    // Dispatch the event to the parent window
    window.parent.dispatchEvent(event);
}

// Trigger the event.
dispatchCustomIFrameLoadedEventToParent();

Then in the CMS template we should be able to resize accordingly when we intercept the events:

window.addEventListener('IFrameInit', () => debouncedResizeIframe(iframe));
window.addEventListener('IFrameLoaded', () => debouncedResizeIframe(iframe));

Note: There is a dash-extensions component named DeferScript that will enable the JS code to be called after the React code has completed loading in Plotly.

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