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
@@ -34,6 +34,8 @@ interface Props {
|
||||
/** Live interval while a range end is dragged. */
|
||||
onRangeDrag?: (range: IntervalRangeHandle, anchor: RoadIntervalAnchor) => void;
|
||||
onRangeEnd?: (range: IntervalRangeHandle, anchor: RoadIntervalAnchor) => void;
|
||||
/** Last solve came back degraded; hold the ghost instead of clearing it. */
|
||||
ghostPending?: boolean;
|
||||
}
|
||||
export function MapCanvas({
|
||||
state,
|
||||
@@ -50,6 +52,7 @@ export function MapCanvas({
|
||||
onHandleBlocked,
|
||||
onRangeDrag,
|
||||
onRangeEnd,
|
||||
ghostPending,
|
||||
}: Props) {
|
||||
const target = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<Map | null>(null);
|
||||
@@ -61,8 +64,8 @@ export function MapCanvas({
|
||||
visibleRef.current = visible;
|
||||
// Callbacks live in refs so the map is built once and never rebuilt when a
|
||||
// parent re-renders with new closures.
|
||||
const dragRef = useRef({ onHandleDrag, onHandleDragEnd, onHandleBlocked, onRangeDrag, onRangeEnd });
|
||||
dragRef.current = { onHandleDrag, onHandleDragEnd, onHandleBlocked, onRangeDrag, onRangeEnd };
|
||||
const dragRef = useRef({ onHandleDrag, onHandleDragEnd, onHandleBlocked, onRangeDrag, onRangeEnd, ghostPending });
|
||||
dragRef.current = { onHandleDrag, onHandleDragEnd, onHandleBlocked, onRangeDrag, onRangeEnd, ghostPending };
|
||||
const selectedRef = useRef<Road | null>(selected);
|
||||
const stateRef = useRef(state);
|
||||
const sceneRef = useRef(scene);
|
||||
@@ -121,6 +124,7 @@ export function MapCanvas({
|
||||
onRangeDrag: (range, anchor) => dragRef.current.onRangeDrag?.(range, anchor),
|
||||
onRangeEnd: (range, anchor) => dragRef.current.onRangeEnd?.(range, anchor),
|
||||
onBlocked: (handle, reason) => dragRef.current.onHandleBlocked?.(handle, reason),
|
||||
holdGhost: () => dragRef.current.ghostPending === true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -164,6 +168,11 @@ export function MapCanvas({
|
||||
// Only the editHandles source is replaced; baseline layers are never touched.
|
||||
handleLayerRef.current?.render(handles ?? [], ranges ?? []);
|
||||
}, [handles, ranges]);
|
||||
useEffect(() => {
|
||||
// A non-degraded answer means the pending ghost has been superseded by real
|
||||
// geometry. Clearing an empty ghost is a no-op, so this is safe mid-drag.
|
||||
if (!ghostPending) ghostRef.current?.clear();
|
||||
}, [ghostPending]);
|
||||
useEffect(() => {
|
||||
const previewLayer = previewRef.current;
|
||||
const baseline = layersRef.current;
|
||||
|
||||
Reference in new issue
Block a user