diff --git a/apps/dotcom/src/components/IFrameProtector.tsx b/apps/dotcom/src/components/IFrameProtector.tsx index d778fbda6..b4fd9f06d 100644 --- a/apps/dotcom/src/components/IFrameProtector.tsx +++ b/apps/dotcom/src/components/IFrameProtector.tsx @@ -114,7 +114,7 @@ export function IFrameProtector({
- {'Visit this page on tldraw.com '} + {'Visit this page on tldraw.com'} { - let showBackToContentPrev = false - - const interval = setInterval(() => { - const renderingShapes = editor.getRenderingShapes() - const renderingBounds = editor.getRenderingBounds() - - // Rendering shapes includes all the shapes in the current page. - // We have to filter them down to just the shapes that are inside the renderingBounds. - const visibleShapes = renderingShapes.filter((s) => { - const maskedPageBounds = editor.getShapeMaskedPageBounds(s.id) - return maskedPageBounds && renderingBounds.includes(maskedPageBounds) - }) - const showBackToContentNow = - visibleShapes.length === 0 && editor.getCurrentPageShapes().length > 0 + useQuickReactor( + 'toggle showback to content', + () => { + const showBackToContentPrev = rIsShowing.current + const shapeIds = editor.getCurrentPageShapeIds() + let showBackToContentNow = false + if (shapeIds.size) { + showBackToContentNow = shapeIds.size === editor.getCulledShapes().size + } if (showBackToContentPrev !== showBackToContentNow) { setShowBackToContent(showBackToContentNow) - showBackToContentPrev = showBackToContentNow + rIsShowing.current = showBackToContentNow } - }, 1000) - - return () => { - clearInterval(interval) - } - }, [editor]) + }, + [editor] + ) if (!showBackToContent) return null