mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #137] feat: optimize barrel imports for RSC-incompatible packages #31
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#31
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gentritbiba on GitHub (Feb 26, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/137
Problem
Barrel imports from packages like
radix-ui,lucide-react,recharts, and others cause crashes in React Server Components (RSC) environments:Root cause: Vite's dev server eagerly evaluates all transitive modules in a barrel. When
import { Slot } from "radix-ui"is encountered, Vite loads all 30+ re-exported sub-packages. Some of these (e.g.,@radix-ui/react-direction) callReact.createContext()at module top-level, which doesn't exist in thereact-servercondition.Next.js avoids this via
experimental.optimizePackageImports— SWC rewrites barrel imports to direct sub-module imports at compile time.Reported in #100.
Solution
Add a
vinext:optimize-importsVite plugin that rewrites barrel imports into direct sub-module imports on the server:The plugin:
export * as X,export { A, B },export { default as X },import * as X; export { X }resolveIdhook so sub-packages resolve correctly under pnpm strict hoistingexperimental.optimizePackageImportsfromnext.configand includes sensible defaults (same list as Next.js)Packages optimized by default
lucide-react,date-fns,lodash-es,rxjs,@headlessui/react,@heroicons/react/20/solid,@heroicons/react/24/solid,@heroicons/react/24/outline,@tremor/react,@mui/material,@mui/icons-material,recharts,react-bootstrap,antd,@ant-design/icons,ahooks,@tabler/icons-react,radix-ui