-
Notifications
You must be signed in to change notification settings - Fork 46
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: show spinner till content isnt visible #210
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,13 +51,30 @@ const addContentListener = slotName => { | |
document.body.setAttribute('name', window.location.hash.slice(1)); | ||
} | ||
|
||
const status = { | ||
hasAddedNodes: false, | ||
hasTextOrOpticNodes: false, | ||
isAnyChildVisible: false, | ||
}; | ||
|
||
const observer = new MutationObserver((mutationsList, observer) => { | ||
const hasAddedNodes = !!mutationsList.find(mutation => mutation.addedNodes.length); | ||
if (!hasAddedNodes) return; | ||
if (!status.hasAddedNodes) { | ||
status.hasAddedNodes = !!mutationsList.find(mutation => mutation.addedNodes.length); | ||
} | ||
|
||
// if we have rendered MS to DOM but meaningful content isn't rendered, e.g. due to essential data preload | ||
if (!status.hasTextOrOpticNodes) { | ||
const hasText = !!targetNode.innerText.trim().length | ||
const hasOpticNodes = !!targetNode.querySelector(':not(div):not(span)'); | ||
status.hasTextOrOpticNodes = hasText || hasOpticNodes; | ||
} | ||
|
||
// if we have rendered MS to DOM but temporary hide it for some reason, e.g. to fetch data | ||
if (!status.isAnyChildVisible) { | ||
status.isAnyChildVisible = Array.from(targetNode.children).some(node => node.style.display !== 'none'); | ||
} | ||
|
||
const hasText = !!targetNode.innerText.trim().length | ||
const hasOpticNodes = !!targetNode.querySelector(':not(div):not(span)'); | ||
if (!hasText && !hasOpticNodes) return; | ||
if (Object.values(status).some(n => !n)) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use if with brackets pls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found myself thinking that we probably do not have any polyfill for Object.values, so this would not work in IE11 |
||
|
||
observer.disconnect(); | ||
contentListeners.splice(contentListeners.indexOf(observer), 1); | ||
|
@@ -67,7 +84,7 @@ const addContentListener = slotName => { | |
const targetNode = getSlotElement(slotName); | ||
targetNode.style.display = 'none'; // we will show all new slots, only when all will be settled | ||
hiddenSlots.push(targetNode); | ||
observer.observe(targetNode, { childList: true, subtree: true }); | ||
observer.observe(targetNode, { childList: true, subtree: true, attributeFilter: ['style'] }); | ||
}; | ||
|
||
const renderFakeSlot = slotName => { | ||
|
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.
IE11 does not support Array.from