Skip to content

fix: reject string CodeBlock theme to surface invalid values at create time#6419

Open
FarhanAliRaza wants to merge 1 commit intoreflex-dev:mainfrom
FarhanAliRaza:code-block-theme
Open

fix: reject string CodeBlock theme to surface invalid values at create time#6419
FarhanAliRaza wants to merge 1 commit intoreflex-dev:mainfrom
FarhanAliRaza:code-block-theme

Conversation

@FarhanAliRaza
Copy link
Copy Markdown
Contributor

@FarhanAliRaza FarhanAliRaza commented Apr 29, 2026

Tightens the CodeBlock.theme prop type from Var[Theme | str] to Var[Theme]. Passing a raw string (e.g. theme="one_dark") silently produced a broken component because the value was never resolved to an actual theme import — now it raises a TypeError at create time, surfacing the mistake immediately.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@FarhanAliRaza FarhanAliRaza requested a review from a team as a code owner April 29, 2026 13:32
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR narrows the theme field of CodeBlock from Var[Theme | str] to Var[Theme], causing a TypeError at component creation time when a plain string is passed. A companion test is added to assert the new behaviour; the .pyi hash is updated accordingly.

The only P2 concern is the existing docstring 'The theme to use (\"light\" or \"dark\").', which still advertises string literals as valid values and would mislead users who encounter the new TypeError.

Confidence Score: 4/5

Safe to merge; the only issue is a stale docstring that still advertises string values.

The implementation is correct and well-tested. The TypeError message format in the framework ("…prop CodeBlock.theme…") matches the test regex r"CodeBlock\.theme". No P0/P1 issues found; one P2 docstring inconsistency keeps the score at 4.

packages/reflex-components-code/src/reflex_components_code/code.py — docstring should be updated to match the new strict type.

Important Files Changed

Filename Overview
packages/reflex-components-code/src/reflex_components_code/code.py Narrows theme field type from `Var[Theme
tests/units/components/datadisplay/test_code.py Adds test verifying TypeError is raised with message matching r"CodeBlock\.theme" when a string is passed for theme; consistent with framework error format "…prop CodeBlock.theme…".
pyi_hashes.json Hash updated to reflect the type annotation change in the generated code.pyi stub file.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["CodeBlock.create(theme=value)"] --> B{Valid Var of Theme?}
    B -- "Yes: Theme.one_dark etc." --> C["Validation passes"]
    B -- "No: plain string passed" --> D["TypeError raised at create time"]
    C --> E["Component instance created"]
    D --> F["Caller sees error immediately"]

    style D fill:#f66,color:#fff
    style F fill:#f66,color:#fff
Loading

Reviews (1): Last reviewed commit: "fix: reject string CodeBlock theme to su..." | Re-trigger Greptile

Comment on lines +390 to 392
theme: Var[Theme] = field(
default=Theme.one_light, doc='The theme to use ("light" or "dark").'
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Misleading docstring conflicts with new type restriction

The doc string 'The theme to use ("light" or "dark").' implies that plain string values like "light" or "dark" are acceptable, which directly contradicts the narrowed type Var[Theme] that now rejects strings at create time. A user following the docstring will hit a TypeError. Consider updating it to reflect the correct usage, e.g. 'The theme to use (e.g. Theme.one_light or Theme.one_dark).'

Suggested change
theme: Var[Theme] = field(
default=Theme.one_light, doc='The theme to use ("light" or "dark").'
)
theme: Var[Theme] = field(
default=Theme.one_light, doc="The theme to use (e.g. Theme.one_light or Theme.one_dark)."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid concern by greptile here

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing FarhanAliRaza:code-block-theme (53c3951) with main (8f7ad9a)

Open in CodSpeed

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.

2 participants