fix(driver): show invalid route upload errors on upload page#212
fix(driver): show invalid route upload errors on upload page#212hir-al-14 wants to merge 1 commit into
Conversation
markboenigk
left a comment
There was a problem hiding this comment.
Overall: Clean direction — removing the deprecated upload screen from /driver_assist and surfacing errors on /upload-route is the right call. A few things worth fixing before merge.
Bug — sessionStorage.setItem can throw inside a catch block
In driver_assist/page.tsx, the import-error handler does:
} catch (importError) {
const message = ...;
clearUploadedRouteFile();
sessionStorage.setItem(ROUTE_UPLOAD_ERROR_KEY, message); // ← throws in private browsing
router.replace("/upload-route");
return;
}sessionStorage.setItem throws a SecurityError in private-browsing mode (iOS Safari, Firefox strict mode) and a QuotaExceededError if storage is full. Because we're already in a catch, the new exception escapes into React — the redirect never runs and the user is stuck. Wrap the setItem + router.replace in a try/catch, or fall back to a query param if storage is unavailable.
Design — parseRouteUploadText result is discarded; the file is parsed twice
In upload-route/page.tsx:
parseRouteUploadText(text); // validated and transformed → result thrown away
sessionStorage.setItem("routeFile", JSON.stringify({ name: file.name, content: text }));
router.push("/driver_assist");Then driver_assist calls loadSessionFromText + transformSessionToDriverRoute on the same string all over again. The two functions are identical in both places, so no behavioral difference today — but this is fragile: any future divergence (extra validation step, schema migration) will silently create inconsistent behavior between pages. Consider storing the already-transformed result in sessionStorage (or at least a comment explaining why re-parsing is intentional).
Nit — ROUTE_UPLOAD_ERROR_KEY belongs in a shared location
driver_assist importing from @/app/upload-route/routeUploadValidation inverts the expected sibling-route boundary. If routeUploadValidation ever gains a transitive import from driver_assist, you have a circular dependency. Moving the constant (and arguably the key itself) to lib/driver-route/ or a shared constants file removes that risk and makes the coupling explicit.
Nit — queueMicrotask wrappers are unnecessary
React 18 batches all setState calls inside useEffect automatically. The queueMicrotask(() => { setRoute(...); setHasCheckedRoute(true); }) pattern in both the success and saved-route branches adds a render-cycle delay and makes the timing harder to reason about without any benefit. Calling the setters directly works identically — same for the queueMicrotask(() => setError(...)) in upload-route/page.tsx.
Summary
/upload-routeinstead of sending drivers to the deprecateddriver_assisttester upload screen.Motivation
/driver_assist, which exposed an old unstyled fallback upload UI.Changes
Frontend:
/upload-routevalidation that parses and transforms route uploads before navigating./upload-routeerror block./upload-routeinstead of rendering the deprecated fallback screen.Backend: No backend changes.
Validation
Frontend
npm.cmd --prefix app/ui run lintnpm.cmd --prefix app/ui run format:checknpm.cmd --prefix app/ui run typechecknpm.cmd --prefix app/ui run testnpm.cmd --prefix app/ui run buildnpm.cmd --prefix app/mobile run lintnpm.cmd --prefix app/mobile run typecheckBackend
cmake --preset dev.github/scripts/check-backend-static.sh build/devcmake --build --preset dev --parallelctest --preset dev --output-on-failure --no-tests=error -LE 'e2e|docker'Risk
/driver_assist./upload-routewith the existing styled error UI.Rollout and Recovery
High-Signal PR Checklist
Related Issues
#198
/upload-routeshows an error on/upload-route./driver_assist.