diff --git a/CHANGELOG.md b/CHANGELOG.md index bb3b2de..19ec7d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Footer is no longer sensitive to `__fold__`--it relies on partial hydration for performance instead. ## [2.20.0] - 2020-03-20 ### Changed diff --git a/react/Footer.js b/react/Footer.js index a7b41d6..10bda79 100644 --- a/react/Footer.js +++ b/react/Footer.js @@ -1,16 +1,10 @@ import React, { Suspense } from 'react' import { ExtensionPoint, useChildBlock, NoSSR } from 'vtex.render-runtime' import { useDevice } from 'vtex.device-detector' -import useFold from './hooks/useFold' const LegacyFooter = React.lazy(() => import('./legacy/Footer')) const Footer = props => { - /** This is a temporary fix--this behaviour is supposed - * to come from render-runtime delayed hydration in the - * future. */ - const shouldRenderBelowTheFold = useFold() - const hasFooterDesktop = !!useChildBlock({ id: 'footer-layout.desktop', }) @@ -20,10 +14,6 @@ const Footer = props => { const { isMobile } = useDevice() - if (!shouldRenderBelowTheFold) { - return null - } - const hasFooterLayout = hasFooterDesktop || hasFooterMobile if (!hasFooterLayout) { diff --git a/react/hooks/useFold.tsx b/react/hooks/useFold.tsx deleted file mode 100644 index 1689662..0000000 --- a/react/hooks/useFold.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { useEffect, useState } from 'react' -import { useRuntime, canUseDOM } from 'vtex.render-runtime' -import { useDevice } from 'vtex.device-detector' - -/** If there is a fold on the page, returns false until the user - * scrolls. This is a temporary hack, until partial hydration - * or something similar becomes available from render-runtime - */ -const useFold = () => { - const { extensions, page } = useRuntime() - const { isMobile } = useDevice() - const rootExtension = extensions[page] - const { blocks } = rootExtension - - const hasFold = blocks?.some(({ extensionPointId }) => - extensionPointId === '__fold__' || - extensionPointId === `__fold__.${isMobile ? 'mobile' : 'desktop'}` - ) ?? false - - const [shouldRender, setShouldRender] = useState(false) - - useEffect(() => { - const handleScroll = () => { - if (!shouldRender) { - setShouldRender(true) - } - } - - if (hasFold && !shouldRender && canUseDOM) { - window.document.addEventListener('scroll', handleScroll) - - return () => { - window.document.removeEventListener('scroll', handleScroll) - } - } - - return - }, [hasFold, shouldRender]) - - return !hasFold || shouldRender -} - -export default useFold