fix(plan): restore pre-plan permission mode reliably (#1170)

This commit is contained in:
paulbettner
2026-02-26 21:01:48 -05:00
committed by GitHub
parent 3f4c689d61
commit 30decee222

View File

@@ -1087,6 +1087,21 @@ export default function App({
const setUiPermissionMode = useCallback((mode: PermissionMode) => {
uiPermissionModeRef.current = mode;
_setUiPermissionMode(mode);
// Keep the permissionMode singleton in sync *immediately*.
//
// We also have a useEffect sync (below) as a safety net, but relying on it
// introduces a render/effect window where the UI can show YOLO while the
// singleton still reports an older mode. That window is enough to break
// plan-mode restoration (plan remembers the singleton's mode-at-entry).
if (permissionMode.getMode() !== mode) {
// If entering plan mode via UI state, ensure a plan file path is set.
if (mode === "plan" && !permissionMode.getPlanFilePath()) {
const planPath = generatePlanFilePath();
permissionMode.setPlanFilePath(planPath);
}
permissionMode.setMode(mode);
}
}, []);
const statusLineTriggerVersionRef = useRef(0);