Declare Lucide deep imports through import_var instead of _get_imports
Follow-up to #7109 and the static-icon deep-import work tracked in #6627.
Icon and DynamicIcon currently implement their deep imports by overriding _get_imports() in packages/reflex-components-lucide/src/reflex_components_lucide/icon.py. Their import_var properties still describe the package-root import inherited from Component.
For example, rx.icon("apple") exposes a named Apple import with package_path="/" through import_var, while _get_imports() replaces it with the actual default import aliased as LucideApple from lucide-react/dist/esm/icons/apple.mjs. DynamicIcon similarly declares /dynamic.mjs only in _get_imports().
Move these import declarations into overrides of the import_var property, allowing the base _get_imports() implementation to assemble them with the component's other imports. Preserve the static icon's default binding, alias, and filename mapping, and the dynamic icon's named DynamicIcon binding and /dynamic.mjs path. This also avoids replacing the entire Lucide entry in the assembled import dictionary.
The latest #7109 change makes bundle_library(component) consume the rendered paths from _get_imports() directly. It therefore already avoids an unnecessary import * as lucide_react from "lucide-react" in root.jsx when a specific icon is registered. This follow-up is a consistency cleanup, not a prerequisite for that fix: import_var should itself describe the module actually imported, so callers using that property can retain the same deep-import optimization.
Validation should cover:
- Static icon
import_varmetadata matches the actual default deep import, including filename overrides and aliases. - Reactive icon
import_varmetadata points to the named import from/dynamic.mjs. - Repeated
_get_imports()calls preserve other imports and return consistent results. - Bundling a specific static icon registers its deep module without the
lucide-reactbarrel; computed components present initially or activated after an event continue to render without introducing an unnecessary barrel import.
Explicit bundle_library("lucide-react") should continue to bundle the package root when requested.
Source: reflex-dev/reflex