Skip to content

Commit

Permalink
fix: removes useUI() dependents sections from LazyLoadingSection (#…
Browse files Browse the repository at this point in the history
…2602)

## What's the purpose of this pull request?

This removes the logic that dynamically loads the sections that depend
on the `useUI()` hook: `CartSidebar` and `RegionModal`. We decided to
try to load them at another moment (//TODO: create a task for it)
instead of on click.

## How to test it?

Try to load the respective sections `CartSidebar` and `RegionModal`
using the [preview
link](https://sfj-2714681--starter.preview.vtex.app/).
You can see that both sections are being loaded in the initial loading
now. Instead of loading after clicking on the respective buttons that
trigger the sections.

### Starters Deploy Preview
- vtex-sites/starter.store#639
- preview https://sfj-2714681--starter.preview.vtex.app/
  • Loading branch information
eduardoformiga authored Dec 20, 2024
1 parent 27b0dd3 commit 1953438
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/core/src/components/cms/RenderSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import SectionBoundary from './SectionBoundary'
import ViewportObserver from './ViewportObserver'
import COMPONENTS from './global/Components'

import { useUI } from '@faststore/ui'

interface Props {
components?: Record<string, ComponentType<any>>
globalSections?: Array<{ name: string; data: any }>
Expand Down Expand Up @@ -55,15 +53,10 @@ export const LazyLoadingSection = ({
sectionName: string
children: ReactNode
}) => {
const { cart: displayCart, modal: displayModal } = useUI()

if (SECTIONS_OUT_OF_VIEWPORT.includes(sectionName)) {
const shouldLoad =
(sectionName === 'CartSidebar' && displayCart) ||
(sectionName === 'RegionModal' && displayModal)

return shouldLoad ? <>{children}</> : null
return <>{children}</>
}

return (
<ViewportObserver sectionName={sectionName}>{children}</ViewportObserver>
)
Expand Down

0 comments on commit 1953438

Please sign in to comment.