Skip to content

Fix: prevent duplicate waypoint creation when reopening sidebar#366

Closed
Shyam-123pandey wants to merge 1 commit intovalhalla:masterfrom
Shyam-123pandey:fix-waypoint-sidebar-bug
Closed

Fix: prevent duplicate waypoint creation when reopening sidebar#366
Shyam-123pandey wants to merge 1 commit intovalhalla:masterfrom
Shyam-123pandey:fix-waypoint-sidebar-bug

Conversation

@Shyam-123pandey
Copy link

@Shyam-123pandey Shyam-123pandey commented Mar 9, 2026

🛠️ Fixes Issue

Closes #365

👨‍💻 Changes proposed

  • Prevent extra waypoint from being added when reopening the sidebar.
  • Added a guard condition before calling addEmptyWaypointToEnd().

📍 Where the change was made

  • File: src/hooks/use-directions-queries.ts
  • Function: reverseGeocode()
  • Updated the condition to ensure a waypoint is only added if it doesn't already exist.

📄 Note to reviewers

Tested by adding multiple waypoints and reopening the sidebar; no duplicate waypoints appear.

📷 Screenshots

Explore Video of Fix:

add.waypont.fix.mp4

Copilot AI review requested due to automatic review settings March 9, 2026 12:48
Copy link

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

This PR fixes a bug where reopening the directions sidebar would trigger duplicate waypoint creation when loading a permalink with 3 or more waypoints. Previously, the reverseGeocode function unconditionally added a new empty waypoint for any permalink index > 1. When the sidebar was reopened while the Zustand store already retained the previously loaded waypoints, these waypoints were added again, producing duplicates. The fix adds a guard that checks whether the store already has a slot for the given index before calling addEmptyWaypointToEnd.

Changes:

  • Added a guard condition in useReverseGeocodeDirections so that addEmptyWaypointToEnd is only called when the store does not yet have a waypoint at the given index.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +153 to 158
if (
options?.isPermalink &&
index > 1 &&
useDirectionsStore.getState().waypoints.length <= index
) {
addEmptyWaypointToEnd();
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

There is no test coverage for the new guard condition added to reverseGeocode. Specifically, the key scenario that motivated this fix — loading a permalink with 3 or more waypoints when the sidebar is reopened (i.e., when waypoints already exist in the store) — is not exercised by any test. The existing directions.spec.tsx URL-parsing tests mock useReverseGeocodeDirections entirely and therefore do not validate the internal logic of the guard condition. A test for reverseGeocode (in the hook itself or via an integration test) should:

  1. Verify that addEmptyWaypointToEnd is called when loading a 3+ waypoint permalink with a fresh (default 2-waypoint) store.
  2. Verify that addEmptyWaypointToEnd is NOT called when the store already has a waypoint at the given index (the reopen scenario).

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

You're right that the current tests in directions.spec.tsx mock useReverseGeocodeDirections, so they don't exercise the internal logic of reverseGeocode. I’ll add a dedicated test to cover the guard condition if You want???
Specifically, I plan to add tests that verify:

  • addEmptyWaypointToEnd is called when loading a permalink with 3+ waypoints on a fresh store (default 2-waypoint state).
  • addEmptyWaypointToEnd is not called when the store already has a waypoint at the given index (e.g., when reopening the sidebar).
    Respond if you want i can add this?

@Shyam-123pandey
Copy link
Author

Please review this PR, Have been successfully fixed this issue.

@nilsnolde nilsnolde closed this Mar 10, 2026
@Shyam-123pandey
Copy link
Author

Hello Sir Please don't be angry , from today onwards i won't do such type of mistake like reminding again again. Can i reopen this PR again?

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] Waypoint populated on reopening the left side panel

3 participants