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
This commit is contained in:
Roger
2026-04-01 01:17:29 +08:00
parent 13b2e92dc8
commit 9cef6af627
3 changed files with 13 additions and 2 deletions

View File

@@ -1,7 +1,8 @@
import { c as _c } from "react/compiler-runtime";
import { feature } from 'bun:bundle';
import figures from 'figures';
import React, { type ReactNode, useEffect, useEffectEvent, useMemo, useRef, useState } from 'react';
import React, { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
import { useEffectEvent } from '../../utils/useEffectEvent.js';
import { isCoordinatorMode } from 'src/coordinator/coordinatorMode.js';
import { useTerminalSize } from 'src/hooks/useTerminalSize.js';
import { useAppState, useSetAppState } from 'src/state/AppState.js';

View File

@@ -1,6 +1,7 @@
import { c as _c } from "react/compiler-runtime";
import { feature } from 'bun:bundle';
import React, { useContext, useEffect, useEffectEvent, useState, useSyncExternalStore } from 'react';
import React, { useContext, useEffect, useState, useSyncExternalStore } from 'react';
import { useEffectEvent } from '../utils/useEffectEvent.js';
import { MailboxProvider } from '../context/mailbox.js';
import { useSettingsChange } from '../hooks/useSettingsChange.js';
import { logForDebugging } from '../utils/debug.js';

View File

@@ -0,0 +1,9 @@
import { useCallback, useRef } from 'react';
// Shim for useEffectEvent (React 19 experimental, not in react-reconciler 0.31)
// Uses useRef to always call the latest callback without re-firing effects
export function useEffectEvent<T extends (...args: any[]) => any>(callback: T): T {
const ref = useRef(callback);
ref.current = callback;
return useCallback(((...args: any[]) => ref.current(...args)) as T, []);
}