Skip to content

fix(web): preserve URL hash when toggling billing cadence#276

Merged
ZappoMan merged 1 commit into
developfrom
mei/fix-275-cadence-toggle-scroll
May 18, 2026
Merged

fix(web): preserve URL hash when toggling billing cadence#276
ZappoMan merged 1 commit into
developfrom
mei/fix-275-cadence-toggle-scroll

Conversation

@mei-artificerinnovations
Copy link
Copy Markdown
Contributor

Problem

Toggling Monthly/Annual on the home page pricing section (/#pricing) causes the page to scroll to the top. Closes #275.

Root cause

setSearchParams in React Router v6 navigates to "?" + newParams, silently dropping the URL hash. On /#pricing, clicking the toggle changes the URL from /#pricing to /?cadence=annual — hash goes from #pricing to "". ScrollToTop's useLayoutEffect([pathname, hash]) re-runs and calls window.scrollTo(0, 0) because the hash is now empty.

Fix

In CadenceToggleView, replace:

setSearch(n, { replace: true });

with:

navigate({ search: n.toString(), hash }, { replace: true });

using useLocation() to read the current hash and pass it through the navigation, so the hash is never dropped.

Regression test

Adds a test in CadenceToggle.web.test.tsx that mounts the toggle inside a MemoryRouter with initial entry /#pricing and asserts that location.hash remains #pricing after clicking both Annual and Monthly buttons.

Test plan

  • Existing CadenceToggle tests pass
  • New regression test passes
  • Manually visit /#pricing on the home page, toggle cadence — page does not scroll to top

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

⚠️ Merge Strategy Reminder

This PR targets the main branch. When merging, please use:

"Create a merge commit" (NOT squash merge)

Using "Squash and merge" on PRs targeting main can cause merge conflicts when merging developmain later.

See https://github.com/Artificer-Innovations/BeakerStack/blob/develop/docs/ARCHITECTURE.md#pull-request-process for details.


Updated at: May 18, 2026 at 3:02 PM PDT

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

CI Coverage & Test Summary

Metric Coverage Covered / Total
Statements 97.27% 12961 / 13325
Branches 81.41% 2440 / 2997
Functions 88.20% 426 / 483
Lines 85.31% 11367 / 13325

Suites: 39 passed, 0 failed (39 total) · Tests: 436 passed, 0 failed (447 total)

✅ All reported test suites passed.

Coverage artifacts: coverage-summary, coverage-packages.


Updated at: May 18, 2026 at 3:22 PM PDT

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a landing-page UX regression where toggling billing cadence in the /#pricing section drops the URL hash, causing the global scroll handler to scroll the page to the top. The approach preserves the current location.hash when updating query params.

Changes:

  • Update CadenceToggleView to navigate while explicitly preserving the current URL hash when toggling cadence.
  • Add a regression test asserting location.hash remains unchanged after toggling cadence from an initial /#pricing entry.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/web/src/components/billing/CadenceToggle.web.tsx Switches from setSearchParams to navigate({ search, hash }) to avoid losing the hash during query updates.
apps/web/src/components/billing/tests/CadenceToggle.web.test.tsx Adds a regression test ensuring the URL hash is preserved across cadence toggles.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/web/src/components/billing/CadenceToggle.web.tsx Outdated
`setSearchParams` in React Router v6 navigates to "?" + newParams,
silently dropping the URL hash. On `/#pricing`, toggling Monthly/Annual
changed the hash from `#pricing` to `""`, causing `ScrollToTop` to fire
and jump to the top of the page.

Fix: replace `setSearch(n, { replace: true })` with
`navigate({ search: n.toString(), hash }, { replace: true })` in
`CadenceToggleView`, reading the current hash from `useLocation()`.

Adds regression test asserting hash is preserved across both toggle
directions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mei-artificerinnovations mei-artificerinnovations force-pushed the mei/fix-275-cadence-toggle-scroll branch from f019874 to 0b5334e Compare May 18, 2026 22:02
@ZappoMan ZappoMan changed the base branch from main to develop May 18, 2026 22:15
@github-actions
Copy link
Copy Markdown
Contributor

Component Status Link
🌐 Web ✅ Deployed Preview →
🗄️ Database ✅ Migrated
💳 Billing ✅ Deployed
📱 Mobile ✅ Deployed

Last deployed: 15:22 PDT


📱 Mobile preview: Channel pr-276

📱 Mobile Preview (OTA Updates)

No native code changes detected - using OTA updates only.

⚠️ Note: This app requires a Development Build (Expo Go will not work due to native Google OAuth).

Step 1: Install Development Build (one-time setup)

  1. Build: npm run mobile:build:dev:ios (or mobile:build:dev:android)
  2. Download from Expo dashboard
  3. Install: EAS_BUILD_PATH=~/Downloads/BeakerStack.ipa npm run mobile:install:dev:ios (iOS) or EAS_BUILD_PATH=~/Downloads/BeakerStack.apk npm run mobile:install:dev:android (Android)

Step 2: Load PR Preview Update

  1. Open the development build on your device/simulator
  2. Shake device (or Cmd+D on iOS / Cmd+M on Android) → "Enter URL manually"
  3. Paste the update URL: https://u.expo.dev/23c5e522-5341-4342-85f5-f2e46dd6087f?channel-name=pr-276
  4. The app will reload with the JavaScript bundle from channel pr-276

Note: You must use the full URL format - just entering the channel name (pr-276) will not work.

Alternative: For local development, use: cd apps/mobile && npx expo start --dev-client, then press 'i' for iOS simulator.

📖 See Mobile Build Testing Guide for detailed instructions.

@ZappoMan ZappoMan merged commit dc44493 into develop May 18, 2026
14 checks passed
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.

bug: home page pricing cadence toggle scrolls page back to top

3 participants