Repository navigation
fix: apply default shikijs transformers when use_transformers=True - #7437
Conversation
ShikiJsTransformer defined its own __init__, which replaced the dataclass-generated one and delegated to ShikiBaseTransformers.__init__, so the subclass defaults (library, fns, style) were never applied and use_transformers=True rendered an empty transformers list. Do the fns/style conversion in __post_init__ instead. Closes reflex-dev#7430
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
Render the default transformer functions in sorted order so the output does not depend on set iteration order, and treat fns=None as an empty list like the previous __init__ did instead of raising TypeError.
|
Thanks, all three addressed in b889847. fns=None: ShikiJsTransformer now treats None as an empty list again, matching what the old init produced, so it no longer raises TypeError. Added test_shiki_js_transformer_fns_none_is_empty. Default order: the default fns are now built from sorted(SHIKIJS_TRANSFORMER_FNS), so the rendered list is the same on every run. The same 10 functions are included and the public constant is unchanged. Test coverage: test_shiki_high_level_code_block_use_transformers now asserts the full rendered transformers list (every default function, in order) and the literal values of the .diff.add/.diff.remove backgrounds, their :after content, and the .highlighted background. |
Merging this PR will not alter performance
|
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
|
potentially breaking, but i honestly doubt we have anyone using this in the real world and if they are, they're using it wrong because they should have been making the FunctionVar themselves the whole time instead of passing raw strs |
All Submissions:
Type of change
Changes To Core Features:
What and why
rx._x.code_block(..., use_transformers=True)renderedtransformers:[]and imported nothing from@shikijs/transformers, so the default transformers (and their.highlighted/ diff styles) were silently dropped.Root cause:
ShikiJsTransformeris a@dataclass(kw_only=True)that defined its own__init__. When the class body already has an__init__,@dataclassdoes not generate one, so the subclass defaults (library, the transformerfns,style) never ran. The custom__init__calledsuper().__init__(**kwargs), i.e. the base dataclass__init__with its empty defaults.ShikiJsTransformer()therefore came out aslibrary='',fns=[],style=None.This most likely started with #5289, which replaced the pydantic base (whose
__init__applied subclass defaults) with a dataclass.Fix: replace the custom
__init__with__post_init__. The generated__init__now applies the subclass defaults, and the samefns/styleconversion runs afterwards.Before / After
Before:
After (default transformers render in sorted name order, so the output is stable across runs):
Tests
Added
test_shiki_high_level_code_block_use_transformers, which asserts the full rendered transformer list and the default diff/highlight styles, andtest_shiki_js_transformer_fns_none_is_empty(fns=Nonegives an empty list, as before). The first fails without the fix and passes with it; the second is a guard for the new__post_init__and also passes on the old code, which already handledfns=None.tests/unitspasses (11254 passed, 159 skipped); ruff check/format and pyright on the touched package are clean. Changelog fragment added forreflex-components-code.Fixes #7430