Skip to content

fix: use shared-state background color to avoid nil pointer (#876)#894

Open
fsorodrigues wants to merge 1 commit into
dlvhdr:mainfrom
fsorodrigues:fix/md-style-nil-pointer-dereference
Open

fix: use shared-state background color to avoid nil pointer (#876)#894
fsorodrigues wants to merge 1 commit into
dlvhdr:mainfrom
fsorodrigues:fix/md-style-nil-pointer-dereference

Conversation

@fsorodrigues
Copy link
Copy Markdown

@fsorodrigues fsorodrigues commented May 21, 2026

Summary

Fixes #876 — TUI crashes with nil pointer dereference of markdownStyle when
BackgroundColorMsg not reached

This PR introduces background color shared state, default and fallback behaviors, and changes to the InitializeMarkdownStyle and GetMarkdownRender functions signatures to ensure that *markdownStyle is never nil when dereferenced.

AI disclosure (per AI_POLICY.md)

Diagnosis of nil pointer dereference location was done with assistance of GPT-5.4 (via OpenCode). Same AI was also used to identify GetMarkdownRender usage extense given the bugfix plan I'm proposing involved altering the function's signature.

Solution

Here are the changes introduced:

internal/tui/context/context.go

  • introduce 2 new fields to the ProgramContext struct: HasDarkBackground bool, BackgroundSource string

interna/tui/markdown/markdownRenderer.go

  • alter InitializeMarkdownStyle and GetMarkdownRenderer signatures to include *context.ProgramContext. These ensure the shared state values ctx.HasBackground and ctx.BackgroundSource are available for the create of the markdown renderer.

internal/tui/ui.go

  • initialize program context with defaults for ctx.HasBackground and ctx.BackgroundSource
  • create fallback behavior that uses lipgloss's compat.HasDarkBackground as boolean for ctx.HasDarkBackground
  • set background color fields in context from tea.BackgroundColorMsg when reached
  • debug log statements with background color values

internal/tui/components/issueview/activity.go
internal/tui/components/issueview/issueview.go
internal/tui/components/prview/activity.go
internal/tui/components/prview/prview.go
internal/tui/modelUtils.go

  • call GetMarkdownRender with context as argument

Testing

Verified the nil pointer derefence panic present on tag v4.24.1 on setup described in #876.

Rebuilt binary with patch (commit 46b5843), removed and reinstalled dash extension from local repo

Started gh dash with debug flag. Verified nil pointer derefence panic is gone and that debug logs describe shared state as expected.

Verified gh dash works normally and renders markdown contents of PRs and issues with expected background

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2026

👋 Hi @fsorodrigues, thanks for the pull request! A scan flagged a concern with it. Could you please take a look?

[pr-task-completion] This PR's body is missing [x] checks on the following tasks from the PR template.

Repositories often provide a set of tasks that pull request authors are expected to complete. Those tasks should be marked as completed with a [x] in the pull request description. Please complete those tasks and mark the checks as [x] completed.

🗺️ This message was posted automatically by OctoGuide: a bot for GitHub repository best practices.

@fsorodrigues fsorodrigues marked this pull request as ready for review May 21, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] TUI crashes with nil pointer dereference when BackgroundColorMsg not reached

1 participant