{"record":{"id":"bf83ecb7a2956798","repo":"reflex-dev/reflex","slug":"transformers-should-be-a-literalvar-type-got-typ","errorCode":null,"errorMessage":"transformers should be a LiteralVar type. Got {type(self.transformers)} instead.","messagePattern":"transformers should be a LiteralVar type\\. Got (.+?) instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-code/src/reflex_components_code/shiki_code_block.py","lineNumber":642,"sourceCode":"            style=Style({**transformer_styles, **BOX_PARENT_STYLING}),\n            **code_wrapper_props,\n        )\n\n    def add_imports(self) -> dict[str, list[str]]:\n        \"\"\"Add the necessary imports.\n        We add all referenced transformer functions as imports from their corresponding\n        libraries.\n\n        Returns:\n            Imports for the component.\n\n        Raises:\n            ValueError: If the transformers are not of type LiteralVar.\n        \"\"\"\n        imports = defaultdict(list)\n        if not isinstance(self.transformers, LiteralVar):\n            msg = f\"transformers should be a LiteralVar type. Got {type(self.transformers)} instead.\"\n            raise ValueError(msg)\n        for transformer in self.transformers._var_value:\n            if isinstance(transformer, ShikiBaseTransformers):\n                imports[transformer.library].extend([\n                    ImportVar(tag=str(fn)) for fn in transformer.fns\n                ])\n                if transformer.library not in self.lib_dependencies:\n                    self.lib_dependencies.append(transformer.library)\n        return imports\n\n    @classmethod\n    def create_transformer(cls, library: str, fns: list[str]) -> ShikiBaseTransformers:\n        \"\"\"Create a transformer from a third party library.\n\n        Args:\n            library: The name of the library.\n            fns: The str names of the functions/callables to invoke from the library.\n\n        Returns:","sourceCodeStart":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-code/src/reflex_components_code/shiki_code_block.py#L624-L660","documentation":"rx.code_block(..., transformers=...) from reflex_components_code requires the transformers argument to be a LiteralVar (built via rx.var/literal from a list of ShikiBaseTransformers) so the component can statically extract the imports each transformer needs. Passing a raw list or other object raises ValueError in add_imports.","triggerScenarios":"Passing a plain Python list of transformer objects (e.g. transformers=[NotationDiff()]) instead of a LiteralVar; passing a computed/route var; leaving an unannotated mutable default.","commonSituations":"Upgrading reflex-components-code where transformers used to accept raw lists; constructing transformer values dynamically from props; passing the result of a non-literal Var operation.","solutions":["Wrap the transformers list in a literal var: transformers=rx.Var([NotationDiff(), Whitespace()]) / LiteralVar.create([...]).","Pass the transformers as literal data so the component can walk transformer.library and transformer.fns at compile time.","Check the component's docs for the accepted transformer classes and construct them accordingly."],"exampleFix":"# before\nrx.code_block(code, language=\"diff\", transformers=[rx.code_block.NotationDiff()])\n\n# after\nfrom reflex.vars import LiteralVar\nrx.code_block(\n    code,\n    language=\"diff\",\n    transformers=LiteralVar.create([rx.code_block.NotationDiff()]),\n)","handlingStrategy":"type-guard","validationCode":"from reflex.vars import LiteralVar\n\ndef transformers_ok(t) -> bool:\n    return isinstance(t, LiteralVar)","typeGuard":"from reflex.vars import LiteralVar\n\ndef is_literal_var(v) -> bool:\n    return isinstance(v, LiteralVar)","tryCatchPattern":null,"preventionTips":["Always wrap transformer lists with LiteralVar.create([...]).","Check component prop types after upgrading reflex-components-code.","Pass transformer instances as literal data, not computed vars."],"tags":["reflex","shiki","code-block","transformers","literal-var"],"backgroundTag":"component-prop-type-mismatch","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}