feat: scope the handle manifest and re-aim the ghost
Two consequences of the preview dropping from ~1535 ms to ~142 ms. The manifest is now scoped to the object being edited. It was 844 KB on a 41-road workspace — 239 handles, 89% of the bytes being `affects` id lists at 46 ids per junction handle — shipped on every preview while the map rendered six. A segment selection returns 12.2 KB, a 69x reduction, and the cost no longer multiplies with each handle kind we are about to add. Omitting the selection keeps the full manifest for the compiler and existing callers, and the tests assert that scoping is a filter of the full manifest rather than a second derivation. The ghost is re-aimed from "estimated geometry" to "what you asked for". Its guide line existed to mark the origin through a long wait that no longer happens, so it is gone; what remains is what the preview cannot say — the numeric delta and whether the drag has hit its clamp. The translucent outline research/joint-solver.md asked for is deliberately not built: drawing it accurately means recomputing the road surface in the browser, which the design forbids, and drawing it crudely would be wrong exactly at transitions, junction boundaries and clamps. A preview that lies is worse than none. `degraded` finally has a consumer. EditSession has tracked it since the session work but nothing read it; a slow solve now dims the ghost in place with a pending label instead of clearing it and letting the geometry flicker, as design.md requires. Selection also fixed a latent hazard: the manifest effect reloads on every selection change, and it used to call session.load() each time, which would have discarded unsaved edits the moment the user clicked another road. It now adopts a document only when the compiled document actually changed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d893e406d6
commit
5292c00926
13 files changed
+305
-41
No files matched your search
@@ -14,6 +14,7 @@ import type {
|
||||
PreviewLayerName,
|
||||
RoadConstraint,
|
||||
RoadEditOperation,
|
||||
EditSelection,
|
||||
RoadIntervalAnchor,
|
||||
VersionConflict,
|
||||
} from './edit/types';
|
||||
@@ -105,16 +106,24 @@ function App() {
|
||||
.catch((error: Error) => setStatus(error.message));
|
||||
}, []);
|
||||
const [manifest, setManifest] = useState<HandleManifest | null>(null);
|
||||
/** Which compiled document the session already adopted, so a re-fetch cannot discard edits. */
|
||||
const loadedDocument = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
// Flag off: no manifest request at all, so the network trace matches main.
|
||||
if (!directEditEnabled) return;
|
||||
api
|
||||
.editState()
|
||||
// Scoped to the selection: the whole-area manifest is 844 KB on a 41-road
|
||||
// workspace, 89% of it `affects` id lists, and the map renders about six.
|
||||
.editState(selected?.segmentId ? { segment: selected.segmentId } : undefined)
|
||||
.then((value) => {
|
||||
if (!('handles' in value)) return;
|
||||
setManifest(value.handles);
|
||||
// The session owns the constraint set from here on, so a drag drafts on top
|
||||
// of the active document instead of sending a lone constraint.
|
||||
// Adopt the document only when it actually changed. This effect also runs on
|
||||
// every selection change, and reloading there would silently discard the
|
||||
// session's unsaved edits.
|
||||
const key = `${value.areaId}:${value.documentVersion}`;
|
||||
if (loadedDocument.current === key) return;
|
||||
loadedDocument.current = key;
|
||||
sessionRef.current?.load(value.document.constraints, value.document.operations, value.documentVersion);
|
||||
touch();
|
||||
})
|
||||
@@ -125,7 +134,7 @@ function App() {
|
||||
// before any area exists and comes back inactive, so the handles never appeared
|
||||
// until a manual reload. A recompile also moves the geometry the manifest
|
||||
// describes, so the manifest has to be refetched with it.
|
||||
}, [state]);
|
||||
}, [state, selected?.segmentId]);
|
||||
const editHandles = useMemo(() => {
|
||||
if (!directEditEnabled || !state) return [];
|
||||
// Handle anchors carry a directional road id while reserves are keyed by
|
||||
@@ -157,6 +166,10 @@ function App() {
|
||||
const [editRevision, setEditRevision] = useState(0);
|
||||
const touch = () => setEditRevision((value) => value + 1);
|
||||
const session = sessionRef.current;
|
||||
// Read at send time so the requester, built once, always scopes to the current
|
||||
// selection without being rebuilt.
|
||||
const selectionRef = useRef<EditSelection | undefined>(undefined);
|
||||
selectionRef.current = selected?.segmentId ? { segment: selected.segmentId } : undefined;
|
||||
/**
|
||||
* One gesture, one operation id. Minted on the first draft of a drag and cleared
|
||||
* on release: reusing an id across gestures would put two operations with the
|
||||
@@ -176,7 +189,7 @@ function App() {
|
||||
if (!owner) return null;
|
||||
return new PreviewRequester({
|
||||
session: owner,
|
||||
send: (request, signal) => api.editPreview(request, signal),
|
||||
send: (request, signal) => api.editPreview({ ...request, selection: selectionRef.current }, signal),
|
||||
onSettled: (outcome, response) => {
|
||||
setEditDiagnostics(response.diagnostics);
|
||||
// The response carries a re-solved manifest. Keeping the stale one made the
|
||||
@@ -471,6 +484,7 @@ function App() {
|
||||
handles={editHandles}
|
||||
ranges={editRanges}
|
||||
preview={preview}
|
||||
ghostPending={session?.degraded ?? false}
|
||||
onHandleDrag={(handle, value) => {
|
||||
const draft = draftFor(handle, value);
|
||||
if (draft) requester?.schedule(draft);
|
||||
|
||||
Reference in new issue
Block a user