Skip to content

Commit 9cef6af

Browse files
committed
fix: useEffectEvent shim for react-reconciler 0.31 compatibility
- Create src/utils/useEffectEvent.ts (useRef + useCallback shim) - Replace react imports of useEffectEvent in BackgroundTasksDialog and AppState - CLI now boots into trust dialog successfully
1 parent 13b2e92 commit 9cef6af

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/components/tasks/BackgroundTasksDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { c as _c } from "react/compiler-runtime";
22
import { feature } from 'bun:bundle';
33
import figures from 'figures';
4-
import React, { type ReactNode, useEffect, useEffectEvent, useMemo, useRef, useState } from 'react';
4+
import React, { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
5+
import { useEffectEvent } from '../../utils/useEffectEvent.js';
56
import { isCoordinatorMode } from 'src/coordinator/coordinatorMode.js';
67
import { useTerminalSize } from 'src/hooks/useTerminalSize.js';
78
import { useAppState, useSetAppState } from 'src/state/AppState.js';

src/state/AppState.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { c as _c } from "react/compiler-runtime";
22
import { feature } from 'bun:bundle';
3-
import React, { useContext, useEffect, useEffectEvent, useState, useSyncExternalStore } from 'react';
3+
import React, { useContext, useEffect, useState, useSyncExternalStore } from 'react';
4+
import { useEffectEvent } from '../utils/useEffectEvent.js';
45
import { MailboxProvider } from '../context/mailbox.js';
56
import { useSettingsChange } from '../hooks/useSettingsChange.js';
67
import { logForDebugging } from '../utils/debug.js';

src/utils/useEffectEvent.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useCallback, useRef } from 'react';
2+
3+
// Shim for useEffectEvent (React 19 experimental, not in react-reconciler 0.31)
4+
// Uses useRef to always call the latest callback without re-firing effects
5+
export function useEffectEvent<T extends (...args: any[]) => any>(callback: T): T {
6+
const ref = useRef(callback);
7+
ref.current = callback;
8+
return useCallback(((...args: any[]) => ref.current(...args)) as T, []);
9+
}

0 commit comments

Comments
 (0)