mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
fix(roadtrip): the vias, the alternatives, the pacing and the missing warning
Choosing another road on a leg that already carried a via appended the new point behind the old one, so the day drove south to the first and north to the second: a zigzag matching neither the line drawn under the button nor the distance printed on it. The alternatives are computed for the two bare endpoints, so the write has to replace the leg, which is what the direct branch beside it already did. A day's vias were only loaded while road-trip mode was being looked at, and the three handlers that re-anchor them after a stop is added, removed or reordered are reachable from the place inspector in both modes. With the switch off they computed their correction from an empty list and wrote nothing, so a deleted stop left the detour on a leg nobody chose, for the traveller and for every collaborator. They are loaded whenever the addon is on now. Seam routing paced itself by sleeping after each request, and storing a result shortened the key its own effect depends on: React tore the effect down mid-sleep, the cleanup aborted it, and the next request went out immediately. Thirteen seams left at round-trip speed, the shared routing hosts refused the tail, and a refused seam changes no state so nothing ever retried it. The wait now happens before the request, against a clock that outlives the effect. The "avoidance not honoured" badge could never appear on the rail: the field behind it was published every round and never written. Only the second engine reports what it achieved against what was asked, and the rail plans in the browser, so it never saw the server's own copy — a motorway crossing read as a motorway-free drive. Two smaller ones. `trip.toast.loadError` has been called since the first commit and exists in no locale, so both call sites printed the key itself; it is written now in all 23. And the phone shell honoured the road-trip session flag while having no rail, no drive lines and no switch to leave it, so narrowing a desktop window took the trip overview away and listed every booked night twice.
This commit is contained in:
@@ -332,6 +332,20 @@ export function useRoadtripRoutes(
|
||||
if (s) daySnaps[stopKey(stop)] = s
|
||||
})
|
||||
}
|
||||
// What was asked for against what the road turned out to be. Only
|
||||
// the second engine reports it, and only when it answered: an OSRM
|
||||
// fallback leaves `avoidance` absent, which is the honest reading
|
||||
// of "the weighting never happened". Collected here because the
|
||||
// rail plans in the browser and never sees the server's own copy
|
||||
// of this field — without it the "not honoured" badge could not
|
||||
// appear at all, and a motorway-free drive that is not one read as
|
||||
// if the setting had held.
|
||||
if (r.avoidance) {
|
||||
const missed = r.avoidance.asked.filter(cls => !r.avoidance!.achieved.includes(cls))
|
||||
if (missed.length) {
|
||||
collectedMisses[day.dayId] = [...new Set([...(collectedMisses[day.dayId] ?? []), ...missed])]
|
||||
}
|
||||
}
|
||||
Object.assign(dayLegs, foldRouteRun(run, stopAt, r, mode))
|
||||
return
|
||||
} catch (err) {
|
||||
@@ -443,6 +457,8 @@ export function useRoadtripRoutes(
|
||||
return out
|
||||
}, [chains, plan, quietDays, window, legsByDay, seamLegs, viasByDay, connectDays])
|
||||
const seamKey = seams.map(s => `${legKey(s.from, s.to)}#${seamShape(s.from, viasByDay)}`).join(';')
|
||||
/** When the last seam request went out, across every run of the effect below. */
|
||||
const lastSeamRequestAt = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (!seams.length) return
|
||||
@@ -450,6 +466,20 @@ export function useRoadtripRoutes(
|
||||
void (async () => {
|
||||
for (const seam of seams) {
|
||||
if (controller.signal.aborted) return
|
||||
// Paced before the request, against a clock that outlives this effect.
|
||||
//
|
||||
// Waiting AFTER one instead spaced nothing: storing a seam changes
|
||||
// seamLegs, which is a dependency of the seams memo, which shortens
|
||||
// seamKey, which is this effect's first dependency — so React tore the
|
||||
// effect down mid-wait, the cleanup aborted the sleep, and the next run
|
||||
// fired straight away. Thirteen seams went out at round-trip speed, the
|
||||
// shared routing hosts answered the tail with 429, and a refused seam
|
||||
// writes no state, so nothing changed to make the effect try again: the
|
||||
// map drew the trip in pieces and the totals came back short.
|
||||
const since = performance.now() - lastSeamRequestAt.current
|
||||
if (since < REQUEST_SPACING_MS) await sleep(REQUEST_SPACING_MS - since, controller.signal)
|
||||
if (controller.signal.aborted) return
|
||||
lastSeamRequestAt.current = performance.now()
|
||||
const mode = resolveLegMode(
|
||||
{ isPlace: true, leg_transport_mode: seam.from.legMode },
|
||||
{ isPlace: true, incoming_leg_transport_mode: seam.to.incomingLegMode },
|
||||
@@ -496,7 +526,6 @@ export function useRoadtripRoutes(
|
||||
// invented. Retried on the next run of this effect.
|
||||
if (controller.signal.aborted) return
|
||||
}
|
||||
await sleep(REQUEST_SPACING_MS, controller.signal)
|
||||
}
|
||||
})()
|
||||
return () => controller.abort()
|
||||
|
||||
Reference in New Issue
Block a user