vtex / faststore

Digital commerce toolkit for frontend developers
https://faststore.dev
MIT License
191 stars 61 forks source link

Feat: new `RenderSections` for all pages #2558

Open eduardoformiga opened 1 week ago

eduardoformiga commented 1 week ago

Depends on

What's the purpose of this pull request?

This PR is part of the performance initiative.

It aims to create a new structure for the RenderSections that uses the ViewportObserver along with the LazyLoadingSection to load the section on demand. Now, the RenderSections receives the globalSection as props, and we are removing the GlobalSection (parent) Component that wraps the pages.

It also applies this structure to all pages:

PS: some changes from PLP and Landing Page need to be applied now. Then I applied some Promise.all and other improvements beforehand.

How to test it?

Now, we can only load the JS for the sections inside the viewport during the first load. You can check the network tab in devtools while scrolling the page until the Footer to double-check the JS for sections above the fold being loaded.

You can run the project locally or use the starter preview to double-check this behavior.

you can test all the pages. The landing page can be accessed through this URL: http://localhost:3000/my-landing-page

https://github.com/user-attachments/assets/8d69faa5-782f-4fb4-81fc-fd637043870b

Performance

Before After
https://starter.vtex.app/ https://sfj-b662675--starter.preview.vtex.app/
on a lucky day (when PSI has a good sense of humor, haha) Screenshot 2024-11-12 at 19 49 50 Screenshot 2024-11-12 at 19 50 00
on a normal day Screenshot 2024-11-12 at 19 54 24 Screenshot 2024-11-12 at 19 54 17

Starters Deploy Preview

preview https://sfj-b662675--starter.preview.vtex.app/

References

In this video, you can see an explanation of loading JS on demand using the Intersection Observer API + code splitting. https://drive.google.com/file/u/1/d/13VYPu45Vaav2ecGmKcFAOUMKAS3pMHd4/view

POC PR

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **faststore-site** | ⬜️ Ignored ([Inspect](https://vercel.com/faststore/faststore-site/Fn7meqpaEJbPHSaRdiPJx6MWJ6pc)) | [Visit Preview](https://faststore-site-git-feat-sfs-1512-and-sfs-1513-99f482-faststore.vercel.app) | | Nov 21, 2024 6:51pm |
codesandbox-ci[bot] commented 1 week ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.