Qwertas
09/03/2025, 5:30 PMstream: false.
The other 50% of the time it works normally. Here is how I use it:
tsx
export function Component() {
const getMyFunction = useGetMyFunction()
console.log(getMyFunction)
useEffect(() => {
getMyFunction.mutate("input")
}, [])
}
It re-renders a few times and fills my schema with null values, then nothing. Not even an error.
The interesting part is that the server function logs the full results parsed from the LLM.
I have logged useBamlAction and it gets stuck at this line const { value, done } = await reader.read()
Any idea?aaronv (BAML)
09/03/2025, 5:32 PMQwertas
09/03/2025, 6:51 PMtsx
export function Component() {
const [tick, setTick] = useState(0)
const getMyFunction = useGetMyFunction()
console.log(getMyFunction)
useEffect(() => {
if (tick === 0) {
setTick((prev) => prev + 1)
}
if (tick === 1) {
useGetMyFunction.mutate("input")
}
}, [tick])
}aaronv (BAML)
09/03/2025, 6:52 PMaaronv (BAML)
09/03/2025, 6:52 PMQwertas
09/03/2025, 6:53 PMaaronv (BAML)
09/03/2025, 6:53 PMaaronv (BAML)
09/03/2025, 6:54 PMQwertas
09/03/2025, 7:21 PMGetMyFunction. The logs only appear a single time.Qwertas
09/03/2025, 7:31 PMtsx
useEffect(() => {
if (tick === 0) {
setTimeout(() => {
setTick((prev) => prev + 1)
}, 1000)
}
if (tick === 1) {
useGetMyFunction.mutate("input")
}
}, [tick, useGetMyFunction.mutate])
`Qwertas
09/03/2025, 7:38 PMuseGetMyFunction.mutate as a dependency, I have an infinite re-render loop. The reason is because useBamlAction does this:
tsx
function useBamlAction<FunctionName extends FunctionNames>(
action: ServerAction,
props: HookInput<FunctionName, { stream?: boolean }> = {},
) {
...
const mutate = useCallback(() => {
...
}, [action, onFinalData, onError, props])
}
Therefore props object reference is recreated every time. I removed the dependency for tinkering right nowaaronv (BAML)
09/03/2025, 8:28 PMgreg (BAML)
09/04/2025, 5:35 PMuseEffect hook twice. I wonder if we can just verify that by adding a console.log right under the call to mutate in your original example?
If we see that, then we can go down the path of hook-debugging (which would probably involve either turning StrictMode off or implementing a cleanup function, IIUC the docs I'm looking at).greg (BAML)
09/04/2025, 5:36 PMmutate in response to form submission. I never stress-tested it with multiple calls in quick succession.Qwertas
09/04/2025, 5:48 PMexport function Component() {
const [tick, setTick] = useState(0)
const getMyFunction = useGetMyFunction()
console.log(getMyFunction)
useEffect(() => {
if (tick === 0) {
setTick((prev) => prev + 1)
}
if (tick === 1) {
useGetMyFunction.mutate("input")
}
}, [tick])
}
Which should only have the condition if (tick === 1) { met once right? Same issue and only one log. Also my useEffect run as soon as the app starts maybe could be an issue. Could you try with a useEffect at the start of you app and see if you get the same issue?greg (BAML)
09/04/2025, 5:49 PMQwertas
09/04/2025, 5:50 PMgreg (BAML)
09/04/2025, 5:51 PM