Describe the bug
When creating a multi-group form, dynamic fields don't always populate correctly when switching to a new group until you press a keyboard input, which triggers an update. This causes dynamic descriptions to be completely blank.
To Reproduce
Tested using huh 0.6.0 as well as the current main branch (c9b2c9cdb7b6c76d636bfdf1d5609818a28779ed) with this reproduction script:
package main
import (
"github.com/charmbracelet/huh"
)
func main() {
path := "initial path"
form := huh.NewForm(
huh.NewGroup(
// Note: behavior is different depending on whether this is an Input or FilePicker; try changing this
// to huh.NewInput() as well.
huh.NewFilePicker().
Title("Select a file").
Value(&path),
),
huh.NewGroup(
huh.NewNote().
DescriptionFunc(
func() string {
return "Selected path: " + path
},
&path,
).
Title("Summary"),
huh.NewConfirm().
Title("Confirm?"),
),
)
if err := form.Run(); err != nil {
panic(err)
}
}
To reproduce:
Create a main.go file with the above contents.
go mod init example
go get github.com/charmbracelet/huh@v0.6.0
go run .
You should now be on the first group with a file picker. Pick any file and press enter.
You should now be on the second group with an empty summary note.
Press any key (e.g. arrow key) and observe that the empty summary note suddenly re-renders with the expected description.
Expected behavior
I expect the "summary" note in the second group to display the dynamic description as soon as the user navigates to that group, like this:
Observed behavior
The "summary" note is completely empty:
Once I press any key on the keyboard, it re-renders and now looks like the first screenshot above, as expected.
Desktop (please complete the following information):
OS: macOS using iTerm
Potential patch?
I was able to resolve the issue by making this patch to trigger updating fields when switching to a new group:
This appears to fix the issue for me and I don't notice any side effects, but it does break a test and I don't fully understand the architecture of this project so it may not be a correct fix.
Additional context
The behavior seems to vary depending on the type of input. If you replace NewFilePicker() with NewInput() in the minimal example, the second group now initially renders empty but then quickly re-renders with the dynamic description. This is different from the FilePicker which never re-renders until you press a key.
Describe the bug When creating a multi-group form, dynamic fields don't always populate correctly when switching to a new group until you press a keyboard input, which triggers an update. This causes dynamic descriptions to be completely blank.
To Reproduce Tested using huh 0.6.0 as well as the current main branch (c9b2c9cdb7b6c76d636bfdf1d5609818a28779ed) with this reproduction script:
To reproduce:
main.go
file with the above contents.go mod init example
go get github.com/charmbracelet/huh@v0.6.0
go run .
Expected behavior I expect the "summary" note in the second group to display the dynamic description as soon as the user navigates to that group, like this:
Observed behavior The "summary" note is completely empty:
Once I press any key on the keyboard, it re-renders and now looks like the first screenshot above, as expected.
Desktop (please complete the following information):
Potential patch?
I was able to resolve the issue by making this patch to trigger updating fields when switching to a new group:
This appears to fix the issue for me and I don't notice any side effects, but it does break a test and I don't fully understand the architecture of this project so it may not be a correct fix.
Additional context
The behavior seems to vary depending on the type of input. If you replace
NewFilePicker()
withNewInput()
in the minimal example, the second group now initially renders empty but then quickly re-renders with the dynamic description. This is different from the FilePicker which never re-renders until you press a key.Screen recording showing the minimal reproduction with
NewInput()
so you can see the flash of missing dynamic fields: https://github.com/user-attachments/assets/d7ae294f-393c-4e89-9769-5207f51c92e0