Skip to content

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

Merged
masenf merged 4 commits intoreflex-dev:mainfrom
FarhanAliRaza:code-block-theme
May 1, 2026
Merged

fix: reject string CodeBlock theme to surface invalid values at create time#6419
masenf merged 4 commits 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 thread packages/reflex-components-code/src/reflex_components_code/code.py
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing FarhanAliRaza:code-block-theme (0fe6a77) with main (76ff38c)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Copy Markdown
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

we should add a test to ensure that rx.color_mode_cond(light=rx.code_block.themes.one_light, dark=rx.code_block.themes.one_dark) can be passed.

check through the docs/ markdown files and doc strings for any examples that might need to be updated. also ensure the docs mention how to access the themes from the CodeBlockNamespace.

FarhanAliRaza and others added 3 commits May 1, 2026 15:15
…e.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…eflex into code-block-theme

# Conflicts:
#	packages/reflex-components-code/src/reflex_components_code/code.py
@FarhanAliRaza FarhanAliRaza requested a review from Alek99 as a code owner May 1, 2026 10:50
@masenf masenf merged commit 6a0bd28 into reflex-dev:main May 1, 2026
69 checks passed
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.

3 participants