Skip to content

Commit 55dbe3f

Browse files
fix: subscribe to draft thread data directly to prevent stale activeDraftThread
The hook selected getDraftThread (a stable function reference) from the composer draft store, then called it at render time to compute activeDraftThread. Because the selector never changed, the component didn't re-render when draftThreadsByThreadId was updated, causing stale closures in handleNewThread and ChatRouteGlobalShortcuts. Fix by subscribing directly to store.draftThreadsByThreadId[routeThreadId] so the component re-renders whenever the draft for the active route thread changes. Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
1 parent a6958f5 commit 55dbe3f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

apps/web/src/hooks/useHandleNewThread.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export function useHandleNewThread() {
1111
const getDraftThreadByProjectId = useComposerDraftStore(
1212
(store) => store.getDraftThreadByProjectId,
1313
);
14-
const getDraftThread = useComposerDraftStore((store) => store.getDraftThread);
1514
const setProjectDraftThreadId = useComposerDraftStore((store) => store.setProjectDraftThreadId);
1615
const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
1716
const clearProjectDraftThreadId = useComposerDraftStore(
@@ -26,7 +25,9 @@ export function useHandleNewThread() {
2625
const activeThread = routeThreadId
2726
? threads.find((thread) => thread.id === routeThreadId)
2827
: undefined;
29-
const activeDraftThread = routeThreadId ? getDraftThread(routeThreadId) : null;
28+
const activeDraftThread = useComposerDraftStore((store) =>
29+
routeThreadId ? (store.draftThreadsByThreadId[routeThreadId] ?? null) : null,
30+
);
3031

3132
const handleNewThread = useCallback(
3233
(

0 commit comments

Comments
 (0)