Skip to content

Commit

Permalink
feat: enable lazy loading skip on custom sections (#2654)
Browse files Browse the repository at this point in the history
## What's the purpose of this pull request?

Enable the store to decide if a new custom section will skip lazy
loading.
It's important because otherwise all sections are inside the
`LazyLoadingSection` and `ViewportObserver` for performance purposes,
which makes the section structure not show on the first HTML - that
being said, sometimes it's important to appear on the first HTML for SEO
purposes.

## How it works?

If the section has a property called `skipLazyLoadingSection` set to
`true` it'll bypass `LazyLoadingSection`.

## How to test it?

I've added a custom section called `Custom H1` in the
`playground.store`, this section is composed by a simple h1 that shows
the collection name. It's already added to the PLP template on hCMS
there, so you can test it through
https://sfj-6854f82--playground.preview.vtex.app/just-arrived - a
collection page on `playground`.
| | |
| ---- | ---- |
| Custom section with `skipLazyLoadingSection` property |
![image](https://github.com/user-attachments/assets/8f3f2130-8168-4d3a-a65d-d0a406388047)
|
| Custom section example |
![image](https://github.com/user-attachments/assets/2ae04efa-42d2-4a82-9d93-a5ae31280ced)
|
| Custom section added to PLP template on hCMS |
![image](https://github.com/user-attachments/assets/79144009-a2f5-4fcf-bbb7-63e6f7263659)
|
| Custom section structure being shown on the 1st HTML |
![image](https://github.com/user-attachments/assets/b0d9ea7b-5bdf-40da-9d40-601f1bd35cf5)
|


### Starters Deploy Preview

https://sfj-6854f82--playground.preview.vtex.app/
([PR](vtex-sites/playground.store#134))

## References

- [Jira task](https://vtex-dev.atlassian.net/browse/SFS-2089)

## Checklist

**Documentation**

- Opened a [doc
request](https://vtex.slack.com/archives/C01664JGV43/p1738258909141509)
with Mari
  • Loading branch information
lariciamota authored Jan 31, 2025
1 parent a5c69a3 commit 2239227
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/core/src/components/cms/RenderSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ const RenderSectionsBase = ({

return (
<SectionBoundary key={`cms-section-${name}-${index}`} name={name}>
<LazyLoadingSection
sectionName={name}
isInteractive={isInteractive}
>
{data.skipLazyLoadingSection ? (
<Component {...data} />
</LazyLoadingSection>
) : (
<LazyLoadingSection
sectionName={name}
isInteractive={isInteractive}
>
<Component {...data} />
</LazyLoadingSection>
)}
</SectionBoundary>
)
})}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/cms/ViewportObserver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function ViewportObserver({
height: VIEWPORT_SIZE, // required to make sections out of the viewport to be rendered on demand
width: '100%',
}}
></div>
/>
)}

{(isVisible || isInteractive) && children}
Expand Down

0 comments on commit 2239227

Please sign in to comment.