Skip to content

Initialize BackToTop visibility on mount#20

Merged
Yasar2019 merged 2 commits into
mainfrom
copilot/initialize-backtotop-visibility-on-mount
Mar 18, 2026
Merged

Initialize BackToTop visibility on mount#20
Yasar2019 merged 2 commits into
mainfrom
copilot/initialize-backtotop-visibility-on-mount

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

BackToTop never called handleScroll() on mount, so the button stayed hidden if the page loaded already scrolled past 400px — requiring a manual scroll event to trigger visibility.

Change

  • Call handleScroll() once immediately after registering the scroll listener to seed the initial visible state:
useEffect(() => {
  const handleScroll = () => setVisible(window.scrollY > 400);
  window.addEventListener("scroll", handleScroll, { passive: true });
  handleScroll(); // initialize on mount
  return () => window.removeEventListener("scroll", handleScroll);
}, []);
Original prompt

This section details on the original issue you should resolve

<issue_title>Initialize BackToTop visibility on mount by calling handleScroll() once</issue_title>
<issue_description>Source: Copilot review comment on PR #8src/Components/BackToTop.jsx line 42

Problem

BackToTop never calls handleScroll() on mount, so if the page loads already scrolled (>400px) the button will remain hidden until the user scrolls again.

Suggested Fix

Call handleScroll() once after registering the listener to initialize visible correctly:

useEffect(() => {
  window.addEventListener('scroll', handleScroll);
  handleScroll(); // initialize on mount
  return () => window.removeEventListener('scroll', handleScroll);
}, []);

Review thread: #8 (comment)</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: Yasar2019 <60102921+Yasar2019@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix BackToTop visibility initialization on mount Initialize BackToTop visibility on mount Mar 15, 2026
Copilot AI requested a review from Yasar2019 March 15, 2026 16:55
@Yasar2019
Copy link
Copy Markdown
Owner

Good

@github-actions
Copy link
Copy Markdown

Azure Static Web Apps: Your stage site is ready! Visit it here: https://witty-mud-031b23a0f-20.eastus2.2.azurestaticapps.net

@Yasar2019 Yasar2019 marked this pull request as ready for review March 18, 2026 00:41
Copy link
Copy Markdown
Owner

@Yasar2019 Yasar2019 left a comment

Choose a reason for hiding this comment

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

Good

@Yasar2019 Yasar2019 merged commit 58ebdc0 into main Mar 18, 2026
2 checks passed
@Yasar2019 Yasar2019 deleted the copilot/initialize-backtotop-visibility-on-mount branch March 18, 2026 00:42
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.

Initialize BackToTop visibility on mount by calling handleScroll() once

2 participants