fix: sync draft route freshness

This commit is contained in:
lda
2026-08-10 01:33:48 +07:00 Verified
parent 14892e89c3
commit ee70397653
4 changed files with 151 additions and 6 deletions
@@ -115,6 +115,13 @@ describe("DraftWorkbench", () => {
expect(screen.getByText("Review needs a route.")).toBeInTheDocument();
});
it("reports the controller's current canonical draft to its route owner", () => {
const onDraftChange = vi.fn();
render(<DraftWorkbench draft={workspace} onDraftChange={onDraftChange} />);
expect(onDraftChange).toHaveBeenCalledWith(workspace);
});
it("keeps the raw draft collapsed and exposes all deferred actions without handlers", () => {
render(<DraftWorkbench draft={workspace} />);
@@ -13,6 +13,7 @@ type DraftWorkbenchProps = {
readonly draft: DraftWorkspace;
readonly capabilities?: ReadonlyArray<CapabilitySummary>;
readonly initialSelection?: WorkbenchSelection;
readonly onDraftChange?: (draft: DraftWorkspace) => void;
readonly onSelectionChange?: (selection: WorkbenchSelection) => void;
readonly enableNavigationProtection?: boolean;
};
@@ -130,6 +131,7 @@ export const DraftWorkbench = ({
draft,
capabilities = EMPTY_CAPABILITIES,
initialSelection = { kind: "canvas" },
onDraftChange,
onSelectionChange,
enableNavigationProtection = false,
}: DraftWorkbenchProps) => {
@@ -138,6 +140,9 @@ export const DraftWorkbench = ({
const [openSheet, setOpenSheet] = useState<MobileSheet | null>(null);
const paletteTriggerRef = useRef<HTMLButtonElement>(null);
const inspectorTriggerRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
onDraftChange?.(controller.draft);
}, [controller.draft, onDraftChange]);
// Resolve capability details from the controller draft so a newly committed
// node can immediately render its edit form before the route-level loader refreshes.
const graph = projectAuthoringGraph(controller.draft.draft);