Fix waypoint loading in Edit in Planner flow
Three issues fixed: 1. GPX parser used browser DOMParser which doesn't exist in Node/Vite SSR. Added async parseGpxAsync() using linkedom for server-side parsing. 2. Server-side session initialization stored waypoints in a Yjs doc instance separate from the Vite WebSocket plugin's doc store. Moved waypoint initialization to client-side: API returns parsed waypoints, client adds them to Yjs after sync. 3. GPX was encoded in URL params causing HTTP 431. Now the Journal creates a Planner session via API (POST body), and only passes compact waypoint coordinates in URL params. Verified: Journal route → Edit in Planner → 4 waypoints loaded, route computed (79.3km), elevation profile, Save to Journal ready. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2e2dbe05c1
commit
14b179bb0c
9 changed files with 201 additions and 13 deletions
|
|
@ -1,3 +1,3 @@
|
|||
export { parseGpx } from "./parse";
|
||||
export { parseGpx, parseGpxAsync } from "./parse";
|
||||
export { generateGpx } from "./generate";
|
||||
export type { GpxData, TrackPoint, ElevationProfile } from "./types";
|
||||
|
|
|
|||
|
|
@ -4,9 +4,39 @@ import type { GpxData, TrackPoint, ElevationProfile } from "./types";
|
|||
/**
|
||||
* Parse a GPX XML string into structured data.
|
||||
*/
|
||||
let _LinkedDOMParser: typeof DOMParser | null = null;
|
||||
|
||||
async function getDOMParser(): Promise<typeof DOMParser> {
|
||||
if (typeof DOMParser !== "undefined") return DOMParser;
|
||||
if (!_LinkedDOMParser) {
|
||||
const linkedom = await import("linkedom");
|
||||
_LinkedDOMParser = linkedom.DOMParser as unknown as typeof DOMParser;
|
||||
}
|
||||
return _LinkedDOMParser;
|
||||
}
|
||||
|
||||
export function parseGpx(xml: string): GpxData {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(xml, "application/xml");
|
||||
// Synchronous path for browser
|
||||
if (typeof DOMParser !== "undefined") {
|
||||
return parseGpxWithParser(new DOMParser(), xml);
|
||||
}
|
||||
// Fallback: try linkedom synchronously (works in Node with top-level await or CJS)
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const { DOMParser: LP } = require("linkedom");
|
||||
return parseGpxWithParser(new LP() as unknown as DOMParser, xml);
|
||||
} catch {
|
||||
throw new Error("DOMParser not available — install linkedom for Node.js");
|
||||
}
|
||||
}
|
||||
|
||||
export async function parseGpxAsync(xml: string): Promise<GpxData> {
|
||||
const Parser = await getDOMParser();
|
||||
return parseGpxWithParser(new Parser(), xml);
|
||||
}
|
||||
|
||||
function parseGpxWithParser(parser: DOMParser, xml: string): GpxData {
|
||||
const doc = parser.parseFromString(xml, "application/xml") as unknown as Document;
|
||||
|
||||
const parserError = doc.querySelector("parsererror");
|
||||
if (parserError) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue