[PR #606] [MERGED] fix(core): guard MarkdownRenderable.getStyle against undefined syntaxStyle #651

Closed
opened 2026-03-02 23:47:31 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/606
Author: @cevr
Created: 2/1/2026
Status: Merged
Merged: 2/2/2026
Merged by: @kommander

Base: mainHead: fix/markdown-getStyle-guard


📝 Commits (1)

  • 3aea717 fix(core): guard MarkdownRenderable.getStyle against undefined syntaxStyle

📊 Changes

1 file changed (+4 additions, -0 deletions)

View changed files

📝 packages/core/src/renderables/Markdown.ts (+4 -0)

📄 Description

Summary

  • Guards MarkdownRenderable.getStyle() against _syntaxStyle being undefined when the Solid reconciler sets content before syntaxStyle

Problem

The @opentui/solid reconciler creates elements with new Element(ctx, { id }) — only { id } is passed in constructor options. Props are then applied via setters in JSX declaration order.

When a consumer writes:

<markdown content={props.content} syntaxStyle={props.syntaxStyle()} ... />

The content setter fires first, triggering updateBlocks()createChunk()getStyle(), which accesses this._syntaxStyle — still undefined because the syntaxStyle setter hasn't run yet.

This crashes with:

TypeError: undefined is not an object (evaluating 'this._syntaxStyle.getStyle')

Note

There's an existing branch fix(solid)-prop-initialization-before-insert that attempts to fix this at the Solid/babel level. This PR takes a complementary approach — defensive guard in MarkdownRenderable itself, so the component is resilient regardless of prop order.

Fix

  • Early-return undefined from getStyle() when _syntaxStyle is uninitialized
  • Blocks render unstyled initially; once syntaxStyle setter runs, _styleDirty triggers rerenderBlocks() on the next render cycle with correct styles

Test plan

  • Verified fix resolves the crash in gent TUI (streaming markdown with <markdown content={...} syntaxStyle={...} />)
  • TypeScript compiles clean (no new errors in Markdown.ts)
  • Visual: markdown renders with correct syntax highlighting after initial unstyled frame

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/606 **Author:** [@cevr](https://github.com/cevr) **Created:** 2/1/2026 **Status:** ✅ Merged **Merged:** 2/2/2026 **Merged by:** [@kommander](https://github.com/kommander) **Base:** `main` ← **Head:** `fix/markdown-getStyle-guard` --- ### 📝 Commits (1) - [`3aea717`](https://github.com/anomalyco/opentui/commit/3aea7179432fd3d36dd1a9907c3d71faab295c9c) fix(core): guard MarkdownRenderable.getStyle against undefined syntaxStyle ### 📊 Changes **1 file changed** (+4 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/renderables/Markdown.ts` (+4 -0) </details> ### 📄 Description ## Summary - Guards `MarkdownRenderable.getStyle()` against `_syntaxStyle` being undefined when the Solid reconciler sets `content` before `syntaxStyle` ## Problem The `@opentui/solid` reconciler creates elements with `new Element(ctx, { id })` — only `{ id }` is passed in constructor options. Props are then applied via setters in **JSX declaration order**. When a consumer writes: ```tsx <markdown content={props.content} syntaxStyle={props.syntaxStyle()} ... /> ``` The `content` setter fires first, triggering `updateBlocks()` → `createChunk()` → `getStyle()`, which accesses `this._syntaxStyle` — still `undefined` because the `syntaxStyle` setter hasn't run yet. This crashes with: ``` TypeError: undefined is not an object (evaluating 'this._syntaxStyle.getStyle') ``` ### Note There's an existing branch `fix(solid)-prop-initialization-before-insert` that attempts to fix this at the Solid/babel level. This PR takes a complementary approach — defensive guard in `MarkdownRenderable` itself, so the component is resilient regardless of prop order. ## Fix - Early-return `undefined` from `getStyle()` when `_syntaxStyle` is uninitialized - Blocks render unstyled initially; once `syntaxStyle` setter runs, `_styleDirty` triggers `rerenderBlocks()` on the next render cycle with correct styles ## Test plan - [x] Verified fix resolves the crash in [gent](https://github.com/cevr/gent) TUI (streaming markdown with `<markdown content={...} syntaxStyle={...} />`) - [x] TypeScript compiles clean (no new errors in `Markdown.ts`) - [ ] Visual: markdown renders with correct syntax highlighting after initial unstyled frame 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:47:31 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#651
No description provided.