Skip to content

fix: apply default shikijs transformers when use_transformers=True - #7437

Merged
masenf merged 4 commits into
reflex-dev:mainfrom
darshjoshi:fix-7430-shiki-use-transformers
Oct 13, 2026
Merged

masenf merged 4 commits into
reflex-dev:mainfrom
darshjoshi:fix-7430-shiki-use-transformers

Conversation

@darshjoshi

@darshjoshi darshjoshi commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)

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?

What and why

rx._x.code_block(..., use_transformers=True) rendered transformers:[] and imported nothing from @shikijs/transformers, so the default transformers (and their .highlighted / diff styles) were silently dropped.

Root cause: ShikiJsTransformer is a @dataclass(kw_only=True) that defined its own __init__. When the class body already has an __init__, @dataclass does not generate one, so the subclass defaults (library, the transformer fns, style) never ran. The custom __init__ called super().__init__(**kwargs), i.e. the base dataclass __init__ with its empty defaults. ShikiJsTransformer() therefore came out as library='', 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 same fns / style conversion runs afterwards.

Before / After

c = rx._x.code_block("print('x') # [!code highlight]", language="python", use_transformers=True)

Before:

['transformers:[]}']
imports: ['shiki@4.5.0', '/components/shiki/code']
ShikiJsTransformer(library='', fns=[], style=None)

After (default transformers render in sorted name order, so the output is stable across runs):

transformers:[(transformerCompactLineOptions()), (transformerMetaHighlight()), ...] (all 10 defaults, sorted)
imports: ['shiki@4.5.0', '@shikijs/transformers@4.5.0', '/components/shiki/code']
ShikiJsTransformer(library='@shikijs/transformers@4.5.0', fns=[FunctionStringVar(...), ...], style=...)

Tests

Added test_shiki_high_level_code_block_use_transformers, which asserts the full rendered transformer list and the default diff/highlight styles, and test_shiki_js_transformer_fns_none_is_empty (fns=None gives 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 handled fns=None. tests/units passes (11254 passed, 159 skipped); ruff check/format and pyright on the touched package are clean. Changelog fragment added for reflex-components-code.

Fixes #7430

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
@darshjoshi
darshjoshi requested a review from a team as a code owner October 6, 2026 05:10

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/reflex-components-code/src/reflex_components_code/shiki_code_block.py Outdated
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Fixes transformer application in code block rendering.

The PR should not merge until explicitly supplied Shiki transformer functions can render without errors.

Findings

  1. P1 Custom transformers fail to render ▶

Summary

The PR restores the Shiki code block’s default transformers and styles, sorts their calls for stable output, and adds coverage for the rendered defaults. The latest change removes supplied-argument normalization, breaking custom transformer inputs.

Reviews (4) · Last reviewed commit: "fix(shiki): drop ShikiJsTransformer.__po..." · Reviewed by Greptile

Comment thread packages/reflex-components-code/src/reflex_components_code/shiki_code_block.py Outdated
Comment thread tests/units/components/datadisplay/test_shiki_code.py Outdated
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.
@darshjoshi

Copy link
Copy Markdown
Contributor Author

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.

@masenf masenf added the bug Something isn't working label Oct 6, 2026

@FarhanAliRaza FarhanAliRaza left a comment

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.

Review notes are in the inline comment.


Generated by Claude Code

Comment thread packages/reflex-components-code/src/reflex_components_code/shiki_code_block.py Outdated
@codspeed

codspeed Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 16 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 148 untouched benchmarks


Comparing darshjoshi:fix-7430-shiki-use-transformers (05088d6) with main (162e5ef)

Open in CodSpeed

@masenf masenf added the on deck PRs lined up to review / merge next label Oct 9, 2026 — with ChatGPT Codex Connector
@greptile-apps

greptile-apps Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@masenf masenf added this to the v0.10.x milestone Oct 9, 2026
@masenf

masenf commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

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

@masenf
masenf merged commit f615739 into reflex-dev:main Oct 13, 2026
146 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

code_block(use_transformers=True) emits an empty Shiki transformer list

3 participants