From 15eddd1959e1a1a8d54ff3fb16c0ca0135135da6 Mon Sep 17 00:00:00 2001 From: Vaibhav Verma Date: Mon, 9 Feb 2026 02:06:37 +0530 Subject: [PATCH] fix(examples): prevent duplicate content on window resize in chat example Fixes content duplication issue when terminal window is resized by handling WindowSizeMsg before passing to child components. Previously, both the viewport and textarea processed resize events independently, causing viewport state to become inconsistent with rendered content. Fixes #1567 --- examples/chat/main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/chat/main.go b/examples/chat/main.go index 6b03a64582..d478870bbe 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -77,9 +77,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { vpCmd tea.Cmd ) - m.textarea, tiCmd = m.textarea.Update(msg) - m.viewport, vpCmd = m.viewport.Update(msg) - switch msg := msg.(type) { case tea.WindowSizeMsg: m.viewport.Width = msg.Width @@ -91,7 +88,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.SetContent(lipgloss.NewStyle().Width(m.viewport.Width).Render(strings.Join(m.messages, "\n"))) } m.viewport.GotoBottom() + m.textarea, tiCmd = m.textarea.Update(msg) + m.viewport, vpCmd = m.viewport.Update(msg) case tea.KeyMsg: + m.textarea, tiCmd = m.textarea.Update(msg) + m.viewport, vpCmd = m.viewport.Update(msg) switch msg.Type { case tea.KeyCtrlC, tea.KeyEsc: fmt.Println(m.textarea.Value()) @@ -107,6 +108,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case errMsg: m.err = msg return m, nil + + default: + m.textarea, tiCmd = m.textarea.Update(msg) + m.viewport, vpCmd = m.viewport.Update(msg) } return m, tea.Batch(tiCmd, vpCmd)