Skip to content

rx.icon static icons emit a lucide-react barrel import, flooding the dev server with ~1700 requests #6627

Closed

Description

@adhami3310

Description

rx.icon with a static string tag (e.g. rx.icon("wifi_off")) compiles to a barrel import from lucide-react:

import { WifiOff } from "lucide-react"

On its own this is fine — Vite tree-shakes it in prod and bundles it into one file in dev. But the moment the app's module graph also contains lucide-react/dynamic.mjs (which rx.icon uses for dynamic / state-Var tags via DynamicIcon), Vite's esbuild dep-optimizer is forced to emit a separate chunk per icon for the dynamic-import map, and esbuild then rewrites the barrel to statically import every one of those ~1500 per-icon chunks.

Because DefaultOverlayComponents (the connection banner, mounted on every page) itself does a barrel import { WifiOff } from "lucide-react", any app that also renders a dynamic icon makes loading any page in dev fire ~1700 network requests — the entire icon library.

Confirmed empirically

Setup Requests on page load (dev)
barrel import alone 1
DynamicIcon alone 1
both together 1715

Reproduction

import reflex as rx


class State(rx.State):
    ic: str = "bell"


def index():
    return rx.vstack(
        rx.icon("wifi_off"),   # static  -> barrel import { WifiOff } from "lucide-react"
        rx.icon(State.ic),     # dynamic -> DynamicIcon from lucide-react/dynamic.mjs
    )


app = rx.App()
app.add_page(index)
  1. reflex run
  2. Open the page in the browser, watch the Network tab.
  3. Observe ~1700 requests, one per icon in lucide-react, instead of the handful actually used.

Note: even an app with only static icons hits this, because the default connection overlay pulls in lucide-react/dynamic.mjs indirectly through rx.icon's shared module.

Expected

Loading a page should only fetch the icons actually used (a handful), not the whole library.

Root cause

The static-string icon codegen emits a named barrel import from lucide-react. Combined with the per-icon dynamic-import map, esbuild expands the barrel into a static import of every icon chunk.

Fix

Emit deep per-icon default imports (lucide's officially recommended form) for the static path, leaving the dynamic (Var → DynamicIcon) path untouched:

// from:
import { WifiOff } from "lucide-react"
// to:
import LucideWifiOff from "lucide-react/dist/esm/icons/wifi-off.mjs"

lucide-react ships no exports map, so the deep path must be lucide-react/dist/esm/icons/<kebab-name>.mjs.

Environment

  • Reflex: main
  • lucide-react: 1.14.0

Activity

  1. added
    bug
    on Jun 8, 2026
  2. linear-code commented on Jun 8, 2026

    @linear-code
  3. added a commit that references this issue on Jun 9, 2026
    6f5c80b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions