mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(planner): scheme-check the booking URL, and stop the serial routing calls
A booking's url is rendered as a plain href to every other member of the trip and nothing ever checked its scheme, so a collaborator could store javascript: there. The place website next to it has been going through safeHttpUrl for exactly this reason, with a comment saying stored values predate the server check - this is the surface that was left. Both ends now: safeHttpUrl at the render site, and the scheme in the shared contract so nothing new gets stored, additively so existing rows still load. The per-leg routing rewrite turned one multi-waypoint request per run into one serial request per leg. A twelve-stop day is eleven round trips to a public OSRM in sequence before a single connector appears, and toggling km/mi does it all again. Group consecutive legs that resolve to the same mode into one request and fire the groups concurrently, keeping leg order on the join. Transport reordering wrote to the store and persisted with a bare catch, so a failed PUT left the sidebar showing an order the server never got; it reconciles now. Plus the smaller ones: the OSM menu_url rendered unchecked, expand/collapse-all persisting to a different storage than the day list reads, the debounced address search with no ordering guard, the accommodation save chain with no error path, and window.__trek_map holding a destroyed map.
This commit is contained in:
@@ -22,6 +22,9 @@ export default function AddressInput({ value, onChange, placeholder, className }
|
||||
const [loading, setLoading] = useState(false)
|
||||
const wrapRef = useRef<HTMLDivElement>(null)
|
||||
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
// Clearing the timer does nothing to a request that is already out, and
|
||||
// mapsApi.search takes no signal, so results are matched by ticket instead.
|
||||
const reqIdRef = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (e: MouseEvent) => {
|
||||
@@ -38,23 +41,28 @@ export default function AddressInput({ value, onChange, placeholder, className }
|
||||
const search = (text: string) => {
|
||||
if (debounceRef.current) clearTimeout(debounceRef.current)
|
||||
const trimmed = text.trim()
|
||||
if (trimmed.length < 3) { setResults([]); setLoading(false); return }
|
||||
// Same reason as in pick(): a request for the longer text may still land.
|
||||
if (trimmed.length < 3) { reqIdRef.current++; setResults([]); setLoading(false); return }
|
||||
debounceRef.current = setTimeout(async () => {
|
||||
const myReq = ++reqIdRef.current
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await mapsApi.search(trimmed, locale)
|
||||
if (myReq !== reqIdRef.current) return
|
||||
setResults(data.places || [])
|
||||
setHighlight(-1)
|
||||
} catch {
|
||||
setResults([])
|
||||
if (myReq === reqIdRef.current) setResults([])
|
||||
} finally {
|
||||
setLoading(false)
|
||||
if (myReq === reqIdRef.current) setLoading(false)
|
||||
}
|
||||
}, 320)
|
||||
}
|
||||
|
||||
const pick = (r: any) => {
|
||||
if (debounceRef.current) clearTimeout(debounceRef.current)
|
||||
// A response still on its way must not repopulate the list behind the pick.
|
||||
reqIdRef.current++
|
||||
onChange(r.address || r.name || '')
|
||||
setOpen(false)
|
||||
setResults([])
|
||||
|
||||
Reference in New Issue
Block a user