fix: use shared-state background color to avoid nil pointer (#876)#894
fix: use shared-state background color to avoid nil pointer (#876)#894fsorodrigues wants to merge 2 commits into
Conversation
|
👋 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
Repositories often provide a set of tasks that pull request authors are expected to complete. Those tasks should be marked as completed with a
|
| func InitializeMarkdownStyle(hasDarkBackground bool) { | ||
| if markdownStyle != nil { | ||
| func InitializeMarkdownStyle(ctx *context.ProgramContext) { | ||
| if markdownStyle != nil && ctx.BackgroundSource == "bubbletea" { |
There was a problem hiding this comment.
I am not sure how this is supposed to work, but wouldn't we want to use the bubbletea background source when the BackgroundColorMsg arrives?
So I'd assume that we'd want to save the background source in a global var next to markdownStyle to know which source initialized it and if it's not nil but the source is compat - initialize it with the new bubbletea source.
Correct me if I'm wrong..
There was a problem hiding this comment.
so... what I had in mind is a progression of "background color" certainty
- in tui/ui.go we set a default state for dark bg / dark bg source when the Model and Context are created. I when with a hardcoded true, which I'm happy for y'all to do whatever initial state you think is right.
- then in InitMsg we can "upgrade" the background color data in the Context using the value from lipgloss compat, which won't be a hardcoded value.
- finally, if/when the tea.BackgroundColorMsg arrives, we have the "most certain" background color to set the style with "finality". The finality being the reason for that addition to the if condition. However, I do see, now, that I made the bubbletea route effectively dead on arrival 🫤
I'll give it another crack in the morning with your suggestion.
There was a problem hiding this comment.
@dlvhdr I think you can have another look.
On the setup that was crashing (wsl + alacritty + tmux), I now see the style initialized with the compat source.
On a setup that never saw the crash (macOs + ghostty + tmux), it follows the expected progression and reaches the bubbletea source.
introduce a new global variable in `internal/tui/markdown/markdownRenderer.go` to track the source used for the markdown style. check if the source already is bubbletea and, if so, return early to avoid an override by a "less confident" source introduce debug logs
Summary
Fixes #876 — TUI crashes with nil pointer dereference of
markdownStylewhenBackgroundColorMsgnot reachedThis PR introduces background color shared state, default and fallback behaviors, and changes to the
InitializeMarkdownStyleandGetMarkdownRenderfunctions signatures to ensure that*markdownStyleis 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
GetMarkdownRenderusage extense given the bugfix plan I'm proposing involved altering the function's signature.Solution
Here are the changes introduced:
internal/tui/context/context.goProgramContextstruct:HasDarkBackgroundbool,BackgroundSourcestringinterna/tui/markdown/markdownRenderer.goInitializeMarkdownStyleandGetMarkdownRenderersignatures to include*context.ProgramContext. These ensure the shared state valuesctx.HasBackgroundandctx.BackgroundSourceare available for the create of the markdown renderer.internal/tui/ui.goctx.HasBackgroundandctx.BackgroundSourcecompat.HasDarkBackgroundas boolean forctx.HasDarkBackgroundtea.BackgroundColorMsgwhen reachedinternal/tui/components/issueview/activity.gointernal/tui/components/issueview/issueview.gointernal/tui/components/prview/activity.gointernal/tui/components/prview/prview.gointernal/tui/modelUtils.goGetMarkdownRenderwith context as argumentTesting
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