Skip to content
Snippets Groups Projects
Commit 0f5c474f authored by stvn's avatar stvn
Browse files

Merge PR #23820 debug/mfe-iframe-resize

* Commits:
  Add logging to Learning MFE iframe, temporarily
parents d435f4cd 2ddc35cd
No related branches found
No related tags found
No related merge requests found
......@@ -115,22 +115,30 @@ ${HTML(fragment.foot_html())}
% endif
% if is_learning_mfe:
## TODO: Remove console.log statements after production debugging
<script type="text/javascript">
(function() {
// If this view is rendered in an iframe within the learning microfrontend app
// it will report the height of its contents to the parent window when the
// document loads, window resizes, or DOM mutates.
console.log('MFE', 'Start script', document.referrer);
if (window !== window.parent) {
document.body.className += ' view-in-mfe';
var lastHeight = window.offsetHeight;
var lastWidth = window.offsetWidth;
var contentElement = document.getElementById('content');
function dispatchResizeMessage() {
function dispatchResizeMessage(event) {
// Note: event is actually an Array of MutationRecord objects
// when fired from the MutationObserver
var eventType = event.type || 'mutate';
console.log('MFE', 'Handle resize', eventType);
var newHeight = contentElement.offsetHeight;
var newWidth = contentElement.offsetWidth;
if (newWidth === lastWidth && newHeight === lastHeight) {
console.log('MFE', 'Ignore resize', newWidth, newHeight, eventType);
return;
}
......@@ -153,6 +161,7 @@ ${HTML(fragment.foot_html())}
// height. This window.scrollTo is an attempt to keep the content at the
// top of the page. See TNL-7094
window.scrollTo(0, 0);
console.log('MFE', 'Did resize', newWidth, newHeight, eventType);
}
// Create an observer instance linked to the callback function
......@@ -163,6 +172,7 @@ ${HTML(fragment.foot_html())}
window.addEventListener('load', dispatchResizeMessage);
window.addEventListener('resize', dispatchResizeMessage);
console.log('MFE', 'Bind events to element', contentElement);
}
}());
</script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment