GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — claude-code-source-code/src/hooks/useDeferredHookMessages.ts at main · chaoswork/claude-code-source-code

Expand file tree

/

useDeferredHookMessages.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
46 lines (43 loc) · 1.46 KB
/

useDeferredHookMessages.ts

Copy path

File metadata and controls

46 lines (43 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useCallback, useEffect, useRef } from 'react'
import type { HookResultMessage, Message } from '../types/message.js'
/**
* Manages deferred SessionStart hook messages so the REPL can render
* immediately instead of blocking on hook execution (~500ms).
*
* Hook messages are injected asynchronously when the promise resolves.
* Returns a callback that onSubmit should call before the first API
* request to ensure the model always sees hook context.
*/
export function useDeferredHookMessages(
pendingHookMessages: Promise<HookResultMessage[]> | undefined,
setMessages: (action: React.SetStateAction<Message[]>) => void,
): () => Promise<void> {
const pendingRef = useRef(pendingHookMessages ?? null)
const resolvedRef = useRef(!pendingHookMessages)
useEffect(() => {
const promise = pendingRef.current
if (!promise) return
let cancelled = false
promise.then(msgs => {
if (cancelled) return
resolvedRef.current = true
pendingRef.current = null
if (msgs.length > 0) {
setMessages(prev => [...msgs, ...prev])
}
})
return () => {
cancelled = true
}
}, [setMessages])
return useCallback(async () => {
if (resolvedRef.current || !pendingRef.current) return
const msgs = await pendingRef.current
if (resolvedRef.current) return
resolvedRef.current = true
pendingRef.current = null
if (msgs.length > 0) {
setMessages(prev => [...msgs, ...prev])
}
}, [setMessages])
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.