Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more simplification, standardize mockNodeModel
  • Loading branch information
sawka committed Mar 18, 2026
commit 9b7af02859a69e211ec032e3d8b2d4d53948fefe
45 changes: 45 additions & 0 deletions frontend/preview/mock/mock-node-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { globalStore } from "@/app/store/jotaiStore";
import type { NodeModel } from "@/layout/index";
import { atom } from "jotai";

export type MockNodeModelOpts = {
nodeId: string;
blockId: string;
innerRect?: { width: string; height: string };
numLeafs?: number;
};

export function makeMockNodeModel(opts: MockNodeModelOpts): NodeModel {
const isFocusedAtom = atom(true);
const isMagnifiedAtom = atom(false);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return {
additionalProps: atom({} as any),
innerRect: atom(opts.innerRect ?? { width: "1000px", height: "640px" }),
blockNum: atom(1),
numLeafs: atom(opts.numLeafs ?? 1),
nodeId: opts.nodeId,
blockId: opts.blockId,
addEphemeralNodeToLayout: () => {},
animationTimeS: atom(0),
isResizing: atom(false),
isFocused: isFocusedAtom,
isMagnified: isMagnifiedAtom,
anyMagnified: atom(false),
isEphemeral: atom(false),
ready: atom(true),
disablePointerEvents: atom(false),
toggleMagnify: () => {
globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom));
},
focusNode: () => {
globalStore.set(isFocusedAtom, true);
},
onClose: () => {},
dragHandleRef: { current: null },
displayContainerRef: { current: null },
};
}
41 changes: 5 additions & 36 deletions frontend/preview/previews/aifilediff.preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import { Block } from "@/app/block/block";
import { globalStore } from "@/app/store/jotaiStore";
import { useWaveEnv } from "@/app/waveenv/waveenv";
import type { NodeModel } from "@/layout/index";
import { atom } from "jotai";
import * as React from "react";
import { makeMockNodeModel } from "../mock/mock-node-model";
import { useRpcOverride } from "../mock/use-rpc-override";
import {
DefaultAiFileDiffChatId,
Expand All @@ -17,38 +15,6 @@ import {

const PreviewNodeId = "preview-aifilediff-node";

function makePreviewNodeModel(blockId: string): NodeModel {
const isFocusedAtom = atom(true);
const isMagnifiedAtom = atom(false);

return {
additionalProps: atom({} as any),
innerRect: atom({ width: "1000px", height: "640px" }),
blockNum: atom(1),
numLeafs: atom(1),
nodeId: PreviewNodeId,
blockId,
addEphemeralNodeToLayout: () => {},
animationTimeS: atom(0),
isResizing: atom(false),
isFocused: isFocusedAtom,
isMagnified: isMagnifiedAtom,
anyMagnified: atom(false),
isEphemeral: atom(false),
ready: atom(true),
disablePointerEvents: atom(false),
toggleMagnify: () => {
globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom));
},
focusNode: () => {
globalStore.set(isFocusedAtom, true);
},
onClose: () => {},
dragHandleRef: { current: null },
displayContainerRef: { current: null },
};
}

export function AiFileDiffPreview() {
const env = useWaveEnv();
const [blockId, setBlockId] = React.useState<string>(null);
Expand All @@ -75,7 +41,10 @@ export function AiFileDiffPreview() {
).then((id) => setBlockId(id));
}, []);
Comment on lines +29 to +42
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing error handling for createBlock promise.

If env.createBlock rejects, the error will be swallowed silently, leaving the component in a perpetual loading state. Consider adding error handling.

🛡️ Add error handling
     React.useEffect(() => {
         env.createBlock(
             {
                 meta: {
                     view: "aifilediff",
                     file: DefaultAiFileDiffFileName,
                     "aifilediff:chatid": DefaultAiFileDiffChatId,
                     "aifilediff:toolcallid": DefaultAiFileDiffToolCallId,
                 },
             },
             false,
             false
-        ).then((id) => setBlockId(id));
+        ).then((id) => setBlockId(id))
+         .catch((err) => console.error("[AiFileDiffPreview] createBlock failed:", err));
     }, []);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
React.useEffect(() => {
env.createBlock(
{
meta: {
view: "aifilediff",
file: DefaultAiFileDiffFileName,
"aifilediff:chatid": DefaultAiFileDiffChatId,
"aifilediff:toolcallid": DefaultAiFileDiffToolCallId,
},
},
});
}, [baseEnv]);
false,
false
).then((id) => setBlockId(id));
}, []);
React.useEffect(() => {
env.createBlock(
{
meta: {
view: "aifilediff",
file: DefaultAiFileDiffFileName,
"aifilediff:chatid": DefaultAiFileDiffChatId,
"aifilediff:toolcallid": DefaultAiFileDiffToolCallId,
},
},
false,
false
).then((id) => setBlockId(id))
.catch((err) => console.error("[AiFileDiffPreview] createBlock failed:", err));
}, []);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/preview/previews/aifilediff.preview.tsx` around lines 29 - 42, The
useEffect calling env.createBlock currently ignores rejection which can leave
the component stuck; update the React.useEffect to handle promise rejections
from env.createBlock by adding a .catch or using try/catch in an async IIFE, and
on error call a recovery path such as setting an error state or logging via
console.error/processLogger and avoid leaving blockId unset; target the
createBlock call and setBlockId usage inside the React.useEffect (or convert to
an async function) so failures are surfaced and the component can render an
error or retry UI.


const nodeModel = React.useMemo(() => (blockId != null ? makePreviewNodeModel(blockId) : null), [blockId]);
const nodeModel = React.useMemo(
() => (blockId != null ? makeMockNodeModel({ nodeId: PreviewNodeId, blockId }) : null),
[blockId]
);

if (blockId == null || nodeModel == null) {
return null;
Expand Down
41 changes: 5 additions & 36 deletions frontend/preview/previews/sysinfo.preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import { Block } from "@/app/block/block";
import { globalStore } from "@/app/store/jotaiStore";
import { handleWaveEvent } from "@/app/store/wps";
import type { NodeModel } from "@/layout/index";
import { atom } from "jotai";
import * as React from "react";
import { makeMockNodeModel } from "../mock/mock-node-model";
import { SysinfoBlockId } from "../mock/mockwaveenv";
import { useRpcOverride } from "../mock/use-rpc-override";
import {
Expand All @@ -18,41 +16,12 @@ import {

const PreviewNodeId = "preview-sysinfo-node";

function makePreviewNodeModel(): NodeModel {
const isFocusedAtom = atom(true);
const isMagnifiedAtom = atom(false);

return {
additionalProps: atom({} as any),
innerRect: atom({ width: "920px", height: "560px" }),
blockNum: atom(1),
numLeafs: atom(2),
nodeId: PreviewNodeId,
blockId: SysinfoBlockId,
addEphemeralNodeToLayout: () => {},
animationTimeS: atom(0),
isResizing: atom(false),
isFocused: isFocusedAtom,
isMagnified: isMagnifiedAtom,
anyMagnified: atom(false),
isEphemeral: atom(false),
ready: atom(true),
disablePointerEvents: atom(false),
toggleMagnify: () => {
globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom));
},
focusNode: () => {
globalStore.set(isFocusedAtom, true);
},
onClose: () => {},
dragHandleRef: { current: null },
displayContainerRef: { current: null },
};
}

export default function SysinfoPreview() {
const historyRef = React.useRef(makeMockSysinfoHistory());
const nodeModel = React.useMemo(() => makePreviewNodeModel(), []);
const nodeModel = React.useMemo(
() => makeMockNodeModel({ nodeId: PreviewNodeId, blockId: SysinfoBlockId, innerRect: { width: "920px", height: "560px" }, numLeafs: 2 }),
[]
);

useRpcOverride("EventReadHistoryCommand", async (_client, data) => {
if (data.event !== "sysinfo" || data.scope !== MockSysinfoConnection) {
Expand Down
41 changes: 5 additions & 36 deletions frontend/preview/previews/web.preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,17 @@
// SPDX-License-Identifier: Apache-2.0

import { Block } from "@/app/block/block";
import { globalStore } from "@/app/store/jotaiStore";
import type { NodeModel } from "@/layout/index";
import { atom } from "jotai";
import * as React from "react";
import { makeMockNodeModel } from "../mock/mock-node-model";
import { WebBlockId } from "../mock/mockwaveenv";

const PreviewNodeId = "preview-web-node";

function makePreviewNodeModel(): NodeModel {
const isFocusedAtom = atom(true);
const isMagnifiedAtom = atom(false);

return {
additionalProps: atom({} as any),
innerRect: atom({ width: "1040px", height: "620px" }),
blockNum: atom(1),
numLeafs: atom(1),
nodeId: PreviewNodeId,
blockId: WebBlockId,
addEphemeralNodeToLayout: () => {},
animationTimeS: atom(0),
isResizing: atom(false),
isFocused: isFocusedAtom,
isMagnified: isMagnifiedAtom,
anyMagnified: atom(false),
isEphemeral: atom(false),
ready: atom(true),
disablePointerEvents: atom(false),
toggleMagnify: () => {
globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom));
},
focusNode: () => {
globalStore.set(isFocusedAtom, true);
},
onClose: () => {},
dragHandleRef: { current: null },
displayContainerRef: { current: null },
};
}

export function WebPreview() {
const nodeModel = React.useMemo(() => makePreviewNodeModel(), []);
const nodeModel = React.useMemo(
() => makeMockNodeModel({ nodeId: PreviewNodeId, blockId: WebBlockId, innerRect: { width: "1040px", height: "620px" } }),
[]
);

return (
<div className="flex w-full max-w-[1100px] flex-col gap-2 px-6 py-6">
Expand Down
Loading