Skip to content

Commit 40c0338

Browse files
fix(ModelPicker): prevent useInput during model loading to avoid yoga-layout WASM error
Error: ``` ⠋ Loading models... Mode: Safe (Shift+Tab to toggle) ❖ Model: gemma4:latest wasm://wasm/000460e2:1 RuntimeError: memory access out of bounds at wasm://wasm/000460e2:wasm-function[215]:0xd5ef at wasm://wasm/000460e2:wasm-function[185]:0xcf8c at X.getComputedWidth (file:///code-ollama/node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js:33:52) at renderer (code-ollama/node_modules/ink/src/renderer.ts:50:37) at onRender (code-ollama/node_modules/ink/src/ink.tsx:533:48) at debounce$1.edges.edges (file:///code-ollama/node_modules/es-toolkit/dist/compat/function/debounce.mjs:18:23) at invoke (file:///code-ollama/node_modules/es-toolkit/dist/function/debounce.mjs:8:18) at onTimerEnd (file:///code-ollama/node_modules/es-toolkit/dist/function/debounce.mjs:15:13) at Timeout._onTimeout (file:///code-ollama/node_modules/es-toolkit/dist/function/debounce.mjs:26:13) at listOnTimeout (node:internal/timers:605:17) ``` Cause: The yoga-layout WASM memory error occurs because the `useInput` hook in ModelPicker was active even while models were loading. When users pressed navigation keys during the "Loading models..." Spinner state, it triggered re-renders that conflicted with yoga-layout's layout calculations, causing the memory access out of bounds error. Fix: Added `isActive: Boolean(options.length)` to the useInput hook to only register keyboard input handling after models are loaded. This prevents the Spinner animation from being interrupted by keyboard events.
1 parent 0dc059c commit 40c0338

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/components/ModelPicker.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ export function ModelPicker({ currentModel, onSelect, onClose }: Props) {
1818
const [error, setError] = useState<string | null>(null);
1919

2020
// close select prompt if current model is chosen
21-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
22-
useInput(async (_input, key) => {
23-
if (!options.length) {
24-
return;
25-
}
26-
27-
if (key.return) {
28-
await time.tick();
29-
onClose();
30-
}
31-
});
21+
useInput(
22+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
23+
async (_input, key) => {
24+
if (key.return) {
25+
await time.tick();
26+
onClose();
27+
}
28+
},
29+
{ isActive: Boolean(options.length) },
30+
);
3231

3332
useEffect(() => {
3433
async function load() {

0 commit comments

Comments
 (0)