Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
80 changes: 19 additions & 61 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "electron-vite";
import path from "path";
import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
import svgr from "vite-plugin-svgr";
import tsconfigPaths from "vite-tsconfig-paths";
Expand All @@ -12,66 +13,6 @@ import tsconfigPaths from "vite-tsconfig-paths";
const CHROME = "chrome140";
const NODE = "node22";

// for debugging
// target is like -- path.resolve(__dirname, "frontend/app/workspace/workspace-layout-model.ts");
function whoImportsTarget(target: string) {
return {
name: "who-imports-target",
buildEnd() {
// Build reverse graph: child -> [importers...]
const parents = new Map<string, string[]>();
for (const id of (this as any).getModuleIds()) {
const info = (this as any).getModuleInfo(id);
if (!info) continue;
for (const child of [...info.importedIds, ...info.dynamicallyImportedIds]) {
const arr = parents.get(child) ?? [];
arr.push(id);
parents.set(child, arr);
}
}

// Walk upward from TARGET and print paths to entries
const entries = [...parents.keys()].filter((id) => {
const m = (this as any).getModuleInfo(id);
return m?.isEntry;
});

const seen = new Set<string>();
const stack: string[] = [];
const dfs = (node: string) => {
if (seen.has(node)) return;
seen.add(node);
stack.push(node);
const ps = parents.get(node) || [];
if (ps.length === 0) {
// hit a root (likely main entry or plugin virtual)
console.log("\nImporter chain:");
stack
.slice()
.reverse()
.forEach((s) => console.log(" ↳", s));
} else {
for (const p of ps) dfs(p);
}
stack.pop();
};

if (!parents.has(target)) {
console.log(`[who-imports] TARGET not in MAIN graph: ${target}`);
} else {
dfs(target);
}
},
async resolveId(id: any, importer: any) {
const r = await (this as any).resolve(id, importer, { skipSelf: true });
if (r?.id === target) {
console.log(`[resolve] ${importer} -> ${id} -> ${r.id}`);
}
return null;
},
};
}

export default defineConfig({
main: {
root: ".",
Expand Down Expand Up @@ -147,8 +88,25 @@ export default defineConfig({
},
},
},
resolve: {
alias: {
"style-to-js$": path.resolve(__dirname, "frontend/style-to-js-compat.ts"),
"extend$": path.resolve(__dirname, "frontend/extend-compat.ts"),
},
},
optimizeDeps: {
include: ["monaco-yaml/yaml.worker.js"],
include: [
"monaco-yaml/yaml.worker.js",
"style-to-js",
"style-to-object",
"react-markdown",
"rehype-raw",
"rehype-sanitize",
"hast-util-to-estree",
"hast-util-to-jsx-runtime",
"extend"
],
exclude: ["mermaid", "streamdown"],
},
server: {
open: false,
Expand Down
26 changes: 18 additions & 8 deletions frontend/app/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,22 @@ const BlockInner = memo((props: BlockProps & { viewType: string }) => {
const waveEnv = useWaveEnv();
const bcm = getBlockComponentModel(props.nodeModel.blockId);
let viewModel = bcm?.viewModel;
if (viewModel == null) {
// viewModel gets the full waveEnv
if (viewModel == null || viewModel.viewType !== props.viewType) {
if (viewModel != null) {
viewModel.dispose?.();
}
viewModel = makeViewModel(props.nodeModel.blockId, props.viewType, props.nodeModel, tabModel, waveEnv);
registerBlockComponentModel(props.nodeModel.blockId, { viewModel });
}
useEffect(() => {
return () => {
unregisterBlockComponentModel(props.nodeModel.blockId);
const currentBcm = getBlockComponentModel(props.nodeModel.blockId);
if (currentBcm?.viewModel === viewModel) {
unregisterBlockComponentModel(props.nodeModel.blockId);
}
viewModel?.dispose?.();
};
}, []);
}, [viewModel]);
Comment on lines +276 to +291

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect dispose() implementations to confirm double-dispose tolerance.
rg -nP -C3 '\bdispose\s*\(' frontend/app/view --type=ts -g '*model*'

Repository: wavetermdev/waveterm

Length of output: 1112


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== block.tsx around reported lines ==\n'
sed -n '250,360p' frontend/app/block/block.tsx

printf '\n== vdom-model.tsx dispose implementation ==\n'
sed -n '180,210p' frontend/app/view/vdom/vdom-model.tsx

printf '\n== term-model.ts dispose implementation ==\n'
sed -n '580,620p' frontend/app/view/term/term-model.ts

Repository: wavetermdev/waveterm

Length of output: 6698


Keep view-model creation/disposal out of render.

BlockInner and SubBlockInner both dispose the previous model, create a new one, and register it during render. That breaks render purity and can trigger extra create/dispose cycles under StrictMode or aborted concurrent renders. The previous effect cleanup then disposes the old instance again, since dispose() here has no repeat-call guard.

Move this transition into an effect or other commit-phase lifecycle so each model is created, registered, and torn down exactly once.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/app/block/block.tsx` around lines 276 - 291, Move the view-model
transition out of render in BlockInner/SubBlockInner: the current conditional
that calls makeViewModel, registerBlockComponentModel, and dispose on the
previous instance during render should be relocated to a commit-phase effect so
rendering stays pure. Update the lifecycle around viewModel,
registerBlockComponentModel, unregisterBlockComponentModel, and the useEffect
cleanup so creation, registration, and disposal happen exactly once per
committed instance, avoiding duplicate dispose calls under StrictMode or aborted
renders.

if (props.preview) {
return <BlockPreview {...props} viewModel={viewModel} />;
}
Expand All @@ -308,17 +313,22 @@ const SubBlockInner = memo((props: SubBlockProps & { viewType: string }) => {
const waveEnv = useWaveEnv();
const bcm = getBlockComponentModel(props.nodeModel.blockId);
let viewModel = bcm?.viewModel;
if (viewModel == null) {
// viewModel gets the full waveEnv
if (viewModel == null || viewModel.viewType !== props.viewType) {
if (viewModel != null) {
viewModel.dispose?.();
}
viewModel = makeViewModel(props.nodeModel.blockId, props.viewType, props.nodeModel, tabModel, waveEnv);
registerBlockComponentModel(props.nodeModel.blockId, { viewModel });
}
useEffect(() => {
return () => {
unregisterBlockComponentModel(props.nodeModel.blockId);
const currentBcm = getBlockComponentModel(props.nodeModel.blockId);
if (currentBcm?.viewModel === viewModel) {
unregisterBlockComponentModel(props.nodeModel.blockId);
}
viewModel?.dispose?.();
};
}, []);
}, [viewModel]);
return <BlockSubBlock {...props} viewModel={viewModel} />;
});
SubBlockInner.displayName = "SubBlockInner";
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/block/blockregistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AiFileDiffViewModel } from "@/app/view/aifilediff/aifilediff";
import { LauncherViewModel } from "@/app/view/launcher/launcher";
import { PreviewModel } from "@/app/view/preview/preview-model";
import { ProcessViewerViewModel } from "@/app/view/processviewer/processviewer";
import { SearchViewModel } from "@/app/view/search/search";
import { SysinfoViewModel } from "@/app/view/sysinfo/sysinfo";
import { TsunamiViewModel } from "@/app/view/tsunami/tsunami";
import { VDomModel } from "@/app/view/vdom/vdom-model";
Expand Down Expand Up @@ -35,6 +36,7 @@ BlockRegistry.set("tsunami", TsunamiViewModel);
BlockRegistry.set("aifilediff", AiFileDiffViewModel);
BlockRegistry.set("waveconfig", WaveConfigViewModel);
BlockRegistry.set("processviewer", ProcessViewerViewModel);
BlockRegistry.set("search", SearchViewModel);

function makeDefaultViewModel(viewType: string): ViewModel {
const viewModel: ViewModel = {
Expand Down
6 changes: 6 additions & 0 deletions frontend/app/block/blockutil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export function blockViewToIcon(view: string): string {
if (view == "processviewer") {
return "microchip";
}
if (view == "search") {
return "search";
}
return "square";
}

Expand Down Expand Up @@ -73,6 +76,9 @@ export function blockViewToName(view: string): string {
if (view == "processviewer") {
return "Processes";
}
if (view == "search") {
return "Search";
}
return view;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/element/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
transformBlocks,
} from "@/app/element/markdown-util";
import remarkMermaidToTag from "@/app/element/remark-mermaid-to-tag";
import { boundNumber, useAtomValueSafe, cn } from "@/util/util";
import { boundNumber, cn, useAtomValueSafe } from "@/util/util";
import clsx from "clsx";
import { Atom } from "jotai";
import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
Expand Down
7 changes: 6 additions & 1 deletion frontend/app/store/keymodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getActiveTabModel } from "@/app/store/tab-model";
import { WorkspaceLayoutModel } from "@/app/workspace/workspace-layout-model";
import { deleteLayoutModelForTab, getLayoutModelForStaticTab, NavigateDirection } from "@/layout/index";
import * as keyutil from "@/util/keyutil";
import { focusedBlockId } from "@/util/focusutil";
import { isWindows } from "@/util/platformutil";
import { CHORD_TIMEOUT } from "@/util/sharedconst";
import { fireAndForget } from "@/util/util";
Expand Down Expand Up @@ -452,7 +453,11 @@ function appHandleKeyDown(waveEvent: WaveKeyboardEvent): boolean {
if (isTabWindow()) {
const layoutModel = getLayoutModelForStaticTab();
const focusedNode = globalStore.get(layoutModel.focusedNode);
const blockId = focusedNode?.data?.blockId;
let blockId = focusedNode?.data?.blockId;
const domFocusedId = focusedBlockId();
if (domFocusedId) {
blockId = domFocusedId;
}
if (blockId != null && shouldDispatchToBlock(waveEvent)) {
const bcm = getBlockComponentModel(blockId);
const viewModel = bcm?.viewModel;
Expand Down
12 changes: 12 additions & 0 deletions frontend/app/store/wshclientapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ export class RpcApiType {
return client.wshRpcCall("filerestorebackup", data, opts);
}

// command "filesearch" [call]
FileSearchCommand(client: WshClient, data: CommandFileSearchData, opts?: RpcOpts): Promise<FileSearchResult[]> {
if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filesearch", data, opts);
return client.wshRpcCall("filesearch", data, opts);
}

// command "filestream" [call]
FileStreamCommand(client: WshClient, data: CommandFileStreamData, opts?: RpcOpts): Promise<FileInfo> {
if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filestream", data, opts);
Expand Down Expand Up @@ -720,6 +726,12 @@ export class RpcApiType {
return client.wshRpcCall("remotefilemultiinfo", data, opts);
}

// command "remotefilesearch" [call]
RemoteFileSearchCommand(client: WshClient, data: CommandFileSearchData, opts?: RpcOpts): Promise<FileSearchResult[]> {
if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefilesearch", data, opts);
return client.wshRpcCall("remotefilesearch", data, opts);
}

// command "remotefilestream" [call]
RemoteFileStreamCommand(client: WshClient, data: CommandRemoteFileStreamData, opts?: RpcOpts): Promise<FileInfo> {
if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefilestream", data, opts);
Expand Down
Loading