Skip to content

[EXPERIMENTAL] feat: FastStore's scroll restoration - #3068

Merged
lucasfp13 merged 15 commits into
devfrom
feat/fs-scroll-restoration
Oct 30, 2025
Merged

lucasfp13 merged 15 commits into
devfrom
feat/fs-scroll-restoration

Conversation

@lucasfp13

@lucasfp13 lucasfp13 commented Oct 14, 2025 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

From a current Next.js's known issue (discussion#44013), these changes aim to add an experimental custom hook to handle scroll restoration when navigating back from PDPs to PLPs.

Screen.Recording.2025-10-09.at.09.46.56.mov

Along with this experimental hook, some adjustments needed to be made to correct the behavior of related components, such as Sentinel.

While the Next.js experimental scrollRestoration flag is not working as it should, we are proposing this FastStore's experimental scroll restoration alternative.

How it works?

While navigating through PLPs and loading more pages, when users navigate to a PDP and navigate back the scroll should be restored to the last position before the navigation.

Starters Deploy Preview

vtex-sites/faststoreqa.store#878

References

#2054

@lucasfp13 lucasfp13 self-assigned this Oct 14, 2025
@lucasfp13
lucasfp13 requested a review from a team as a code owner October 14, 2025 14:12
@lucasfp13
lucasfp13 requested review from ommeirelles and renatamottam and removed request for a team October 14, 2025 14:12
@codesandbox-ci

codesandbox-ci Bot commented Oct 14, 2025 •

Copy link
Copy Markdown

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.

@lucasfp13
lucasfp13 requested review from eduardoformiga, hellofanny, lariciamota and matheusps and removed request for renatamottam October 14, 2025 14:21

@eduardoformiga eduardoformiga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I tested it now (mobile and desktop) and it worked in build/serve mode.

// TODO: We won't need to enable this experimental feature when migrating to Next.js 13
experimental: {
scrollRestoration: true,
scrollRestoration: !storeConfig.experimental.scrollRestoration,

@eduardoformiga eduardoformiga Oct 14, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be the opposite here? Sounds a little confusing to me.
EDIT: I think I've got it now. When we enable using the experimental feature, we should turn off the next.config one, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduardoformiga that's right!

@lemagnetic

Copy link
Copy Markdown
Contributor

I tested your PR on mobile (Safari).
The scroll is restored after navigating back, but not exactly to the same position — it usually ends up a bit higher on the list.
In some cases, I also noticed slightly different behaviors: once it jumped further up the list, and another time it landed past the end of the list.

ScreenRecording_10-21-2025.14-35-25_1.MP4

@matheusps
matheusps changed the base branch from main to dev October 27, 2025 17:28
@lucasfp13
lucasfp13 merged commit 8426a50 into dev Oct 30, 2025
@lucasfp13
lucasfp13 deleted the feat/fs-scroll-restoration branch October 30, 2025 17:39
@lucasfp13 lucasfp13 changed the title feat: FastStore's scroll restoration (experimental) [EXPERIMENTAL] feat: FastStore's scroll restoration Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants