Fixing code_tag_props in rx.code_block#5779
Conversation
There was a problem hiding this comment.
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
CodSpeed Performance ReportMerging #5779 will not alter performanceComparing Summary
|
The downgrade to
react-syntax-highlighter@15.6.1(#4368) does not actually fix the issue withwrap_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 usepre-wrapinstad ofpre, but thecode_tag_propsonly accepts adict[str, str]which prevents a successful style override ofcode_tag_props={"style": {"white-space": "pre-wrap"}}.This PR changes the type hinting of
code_tag_props: rx.Var[dict[str, str]]tocode_tag_props: rx.Var[dict[str, str | dict[str, str]]]so the component renderer doesn't throw a fit. Thewrap_long_lineskeyword argument will still not work with Prism, but this will allow users to override the<code>styling.All Submissions:
Type of change
Please delete options that are not relevant.
After these steps, you're ready to open a pull request.