0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-15 23:32:41 +00:00

Simplify observer

This commit is contained in:
Trevor Buckner
2024-10-22 13:58:35 -04:00
parent 9fbdd24d01
commit 83a48b8d0c

View File

@@ -85,21 +85,17 @@ const BrewRenderer = (props)=>{
anchor.scrollIntoView({ behavior: 'smooth' }); anchor.scrollIntoView({ behavior: 'smooth' });
} else { } else {
// Use MutationObserver to wait for the element if it's not immediately available // Use MutationObserver to wait for the element if it's not immediately available
const observer = new MutationObserver((mutations, obs) => { new MutationObserver((mutations, obs) => {
anchor = iframeDoc.querySelector(hash); anchor = iframeDoc.querySelector(hash);
if (anchor) { if (anchor) {
anchor.scrollIntoView({ behavior: 'smooth' }); anchor.scrollIntoView({ behavior: 'smooth' });
obs.disconnect(); obs.disconnect();
} }
}); }).observe(iframeDoc, {
if (iframeDoc.body) {
observer.observe(iframeDoc.body, {
childList : true, childList : true,
subtree : true, subtree : true,
}); });
} }
}
}; };
const updateCurrentPage = useCallback(_.throttle((e)=>{ const updateCurrentPage = useCallback(_.throttle((e)=>{