{"record":{"id":"b711525925191cf5","repo":"reflex-dev/reflex","slug":"component-must-have-a-library-to-bundle","errorCode":null,"errorMessage":"Component must have a library to bundle.","messagePattern":"Component must have a library to bundle\\.","errorType":"exception","errorClass":"DynamicComponentMissingLibraryError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/components/dynamic.py","lineNumber":51,"sourceCode":"    bundled[:] = _default_bundled_libraries()\n\n\ndef bundle_library(component: Union[\"Component\", str]):\n    \"\"\"Bundle a library with the component.\n\n    Args:\n        component: The component to bundle the library with.\n\n    Raises:\n        DynamicComponentMissingLibraryError: Raised when a dynamic component is missing a library.\n    \"\"\"\n    bundled = RegistrationContext.ensure_context().bundled_libraries\n    if isinstance(component, str):\n        bundled.append(format_library_name(component))\n        return\n    if component.library is None:\n        msg = \"Component must have a library to bundle.\"\n        raise DynamicComponentMissingLibraryError(msg)\n    bundled.append(format_library_name(component.library))\n\n\ndef load_dynamic_serializer():\n    \"\"\"Load the serializer for dynamic components.\"\"\"\n    # Causes a circular import, so we import here.\n    from reflex_base.components.component import Component\n\n    @serializer\n    def make_component(component: Component) -> str:\n        \"\"\"Generate the code for a dynamic component.\n\n        Args:\n            component: The component to generate code for.\n\n        Returns:\n            The generated code\n        \"\"\"","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/components/dynamic.py#L33-L69","documentation":"After unpickling, the stored substate schema string is compared with the current class's `_to_schema()`. A mismatch raises StateSchemaMismatchError, guarding against unpickling state written by a different app/schema version.","triggerScenarios":"Loading pickled state (from redis or custom storage) where fields/substates changed since it was serialized — renamed vars, added/removed substates, reordered fields.","commonSituations":"Deploying a new version with changed State classes while users' tokens persist in redis; local dev against a redis instance holding old-schema state.","solutions":["Flush the affected redis keys (or bump the redis db / token prefix) so fresh state is generated","Keep schema changes backward compatible by avoiding renames/removals of existing fields","Catch StateSchemaMismatchError and recreate default state for the token"],"exampleFix":"// before\nstate = await StateRoot.deserialize(data=pickled)\n// after\ntry:\n    state = StateRoot.deserialize(data=pickled)\nexcept StateSchemaMismatchError:\n    state = StateRoot()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    state = StateRoot.deserialize(data=pickled)\nexcept StateSchemaMismatchError:\n    state = StateRoot()  # reset token state after schema change","preventionTips":["Flush redis tokens after state schema changes","Use separate redis db per app version during migration"],"tags":["reflex","state","pickle","schema-version"],"backgroundTag":"schema-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}