Skip to content

Fixing code_tag_props in rx.code_block#5779

Merged
adhami3310 merged 1 commit intoreflex-dev:mainfrom
riebecj:main
Sep 11, 2025
Merged

Fixing code_tag_props in rx.code_block#5779
adhami3310 merged 1 commit intoreflex-dev:mainfrom
riebecj:main

Conversation

@riebecj
Copy link
Contributor

@riebecj riebecj commented Sep 10, 2025

The downgrade to react-syntax-highlighter@15.6.1 (#4368) does not actually fix the issue with wrap_long_lines (see this issue). There isn't an issue with the default HighlightJS, but there is one with Prism. Based on this comment one could overwrite the code tag style to use pre-wrap instad of pre, but the code_tag_props only accepts a dict[str, str] which prevents a successful style override of code_tag_props={"style": {"white-space": "pre-wrap"}}.

This PR changes the type hinting of code_tag_props: rx.Var[dict[str, str]] to code_tag_props: rx.Var[dict[str, str | dict[str, str]]] so the component renderer doesn't throw a fit. The wrap_long_lines keyword argument will still not work with Prism, but this will allow users to override the <code> styling.

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)

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

b. Describe your changes.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR addresses a type hint limitation in the CodeBlock component's code_tag_props field that was preventing users from applying CSS style overrides. The main change expands the type signature from Var[dict[str, str]] to Var[dict[str, str | dict[str, str]]], allowing nested dictionary values.

The context for this change relates to an ongoing issue with the wrap_long_lines feature in react-syntax-highlighter when using Prism. While the feature works with HighlightJS, it's broken with Prism in recent versions. A workaround exists where users can manually override the code tag's CSS by passing code_tag_props={"style": {"white-space": "pre-wrap"}}, but the restrictive type hint was blocking this approach.

The PR also updates the react-syntax-highlighter library version from 15.6.1 to 15.6.6, continuing efforts to resolve the underlying issue, though the PR notes this doesn't fully fix the Prism-specific problem.

Additionally, the pyi_hashes.json file is updated to reflect the type hint changes in the corresponding stub file, ensuring the type checking infrastructure remains synchronized with the code changes. This maintains the integrity of Reflex's type system while enabling the workaround functionality.

Confidence score: 4/5

  • This PR is safe to merge with low risk as it expands type flexibility without breaking existing functionality
  • Score reflects a straightforward type expansion that maintains backward compatibility while enabling user workarounds for a known library issue
  • Pay close attention to the CodeBlock component to ensure the broader type acceptance doesn't cause runtime issues with unexpected nested structures

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 10, 2025

CodSpeed Performance Report

Merging #5779 will not alter performance

Comparing riebecj:main (5fa56c7) with main (caab8ba)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 merged commit f0b2075 into reflex-dev:main Sep 11, 2025
41 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