Skip to content

Scroll to top when navigating between recipes#91

Merged
ghidalgo3 merged 1 commit into
mainfrom
scroll-top-on-recipe-change
Jun 15, 2026
Merged

Scroll to top when navigating between recipes#91
ghidalgo3 merged 1 commit into
mainfrom
scroll-top-on-recipe-change

Conversation

@ghidalgo3

Copy link
Copy Markdown
Owner

Summary

Tapping a recommended recipe at the bottom of a recipe page navigates to another recipe, but the user stays scrolled near the bottom instead of seeing the top of the new recipe.

The cause: recipe pages all share the /recipes/details pathname and differ only by the ?id= query param, so React Router treats it as the same location and never resets the scroll position.

Fix

Added a useEffect in RecipePage keyed on recipeId that calls window.scrollTo(0, 0) whenever the recipe changes. This covers tapping a recommended recipe as well as any other in-app navigation between recipes (e.g. from the History page).

Test plan

  • Open a recipe, scroll to the "Recommended Recipes" section, tap a card → the new recipe page is shown scrolled to the top.
  • Normal navigation into a recipe from the home page still lands at the top.

🤖 Generated with Claude Code

Tapping a recommended recipe navigates to the same /recipes/details
pathname with a different ?id= query, so React Router does not reset the
scroll position and the user lands mid-page. Scroll to the top whenever
the recipe id changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ghidalgo3
ghidalgo3 merged commit 4810eae into main Jun 15, 2026
3 checks passed
@ghidalgo3
ghidalgo3 deleted the scroll-top-on-recipe-change branch June 15, 2026 02:38
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.

1 participant