[PR #847] fix(plugins): resolve optimized imports past local barrels #895

Open
opened 2026-05-06 13:10:42 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/847
Author: @llc1123
Created: 4/15/2026
Status: 🔄 Open

Base: mainHead: fix/issue-845-optimize-imports


📝 Commits (10+)

  • 012c532 fix(plugins): resolve optimized imports past local barrels
  • e8079c8 test: cover antd App Router build regression
  • e9fe4c3 fix(plugins): parse JSX before optimize-import rewriting
  • 68e0eff test: cover JSX-bearing optimize-import transforms
  • 34ef836 test: strengthen optimize-imports build assertions
  • 1c2d1ee fix(plugins): avoid phantom fallback exports
  • da5fd92 fix(plugins): guard export-map reentry during barrel analysis
  • 9caf7fe test: split optimize-imports transform coverage
  • 2394156 test: split optimize-imports export-map basics
  • 5109d7b test: split optimize-imports export-map recursion cases

📊 Changes

10 files changed (+1200 additions, -732 deletions)

View changed files

📝 packages/vinext/src/plugins/optimize-imports.ts (+312 -37)
tests/optimize-imports-build.test.ts (+188 -0)
tests/optimize-imports-export-map-bindings.test.ts (+56 -0)
tests/optimize-imports-export-map-failures.test.ts (+48 -0)
tests/optimize-imports-export-map-recursion.test.ts (+117 -0)
tests/optimize-imports-export-map-reexports.test.ts (+67 -0)
tests/optimize-imports-export-map-wildcards.test.ts (+100 -0)
tests/optimize-imports-plugin.test.ts (+127 -0)
tests/optimize-imports-regressions.test.ts (+159 -0)
📝 tests/optimize-imports.test.ts (+26 -695)

📄 Description

Summary

  • fix optimize-imports so optimized package imports keep following local re-export chains to the concrete leaf module instead of stopping at an intermediate barrel like antd/es/button/index.js
  • flatten local export * boundaries inside optimized packages before downstream graph analysis so @vitejs/plugin-rsc no longer sees the issue-845 client-boundary shape
  • add both a targeted transform regression and an App Router production-build regression covering the antd repro path

Validation

  • ./node_modules/.bin/vp test run tests/optimize-imports.test.ts -t "multi-hop antd barrel"
  • ./node_modules/.bin/vp test run tests/optimize-imports-build.test.ts

Issue

Fixes #845.

Current solution

The bug happened because vinext:optimize-imports used to stop at an intermediate local barrel (antd/es/button/index.js). That file is a "use client" boundary with export *, so @vitejs/plugin-rsc later failed with unsupported ExportAllDeclaration.

The fix keeps the rewrite generic rather than antd-specific:

  • recursively resolve local re-exports until the concrete implementation file is reached
  • safely flatten local wildcard re-exports inside optimized packages before plugin-rsc inspects them
  • fall back to a conservative direct-export map when parsing a JSX-bearing .js leaf fails, so the local-barrel walk can still reach the leaf module

This means the app import now rewrites to the concrete leaf module instead of leaking the intermediate export * barrel into the RSC build.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/847 **Author:** [@llc1123](https://github.com/llc1123) **Created:** 4/15/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/issue-845-optimize-imports` --- ### 📝 Commits (10+) - [`012c532`](https://github.com/cloudflare/vinext/commit/012c53270cb6f9f962fb1183b18b077261ee658b) fix(plugins): resolve optimized imports past local barrels - [`e8079c8`](https://github.com/cloudflare/vinext/commit/e8079c8e6d003d824eb7bd08099f3e7c9a0ef0df) test: cover antd App Router build regression - [`e9fe4c3`](https://github.com/cloudflare/vinext/commit/e9fe4c3f69433be1fb216feec5eccd3e51e26e98) fix(plugins): parse JSX before optimize-import rewriting - [`68e0eff`](https://github.com/cloudflare/vinext/commit/68e0effb56306093e2279bc7cfed4132724a5528) test: cover JSX-bearing optimize-import transforms - [`34ef836`](https://github.com/cloudflare/vinext/commit/34ef8368bd46f826ccc869f6d51ba80b639aa179) test: strengthen optimize-imports build assertions - [`1c2d1ee`](https://github.com/cloudflare/vinext/commit/1c2d1ee47b8a11d75cf18230e8cb4c3d1b3ed4eb) fix(plugins): avoid phantom fallback exports - [`da5fd92`](https://github.com/cloudflare/vinext/commit/da5fd924ef8328064f60ccd5f7f75c1b1b129f73) fix(plugins): guard export-map reentry during barrel analysis - [`9caf7fe`](https://github.com/cloudflare/vinext/commit/9caf7fe75f997159da725b65945aabe00d8487fa) test: split optimize-imports transform coverage - [`2394156`](https://github.com/cloudflare/vinext/commit/23941563fa200887efc13f531779e28f978ecc7d) test: split optimize-imports export-map basics - [`5109d7b`](https://github.com/cloudflare/vinext/commit/5109d7b3efe717b9b601820d8e9bf39fd98842c3) test: split optimize-imports export-map recursion cases ### 📊 Changes **10 files changed** (+1200 additions, -732 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/plugins/optimize-imports.ts` (+312 -37) ➕ `tests/optimize-imports-build.test.ts` (+188 -0) ➕ `tests/optimize-imports-export-map-bindings.test.ts` (+56 -0) ➕ `tests/optimize-imports-export-map-failures.test.ts` (+48 -0) ➕ `tests/optimize-imports-export-map-recursion.test.ts` (+117 -0) ➕ `tests/optimize-imports-export-map-reexports.test.ts` (+67 -0) ➕ `tests/optimize-imports-export-map-wildcards.test.ts` (+100 -0) ➕ `tests/optimize-imports-plugin.test.ts` (+127 -0) ➕ `tests/optimize-imports-regressions.test.ts` (+159 -0) 📝 `tests/optimize-imports.test.ts` (+26 -695) </details> ### 📄 Description ## Summary - fix `optimize-imports` so optimized package imports keep following local re-export chains to the concrete leaf module instead of stopping at an intermediate barrel like `antd/es/button/index.js` - flatten local `export *` boundaries inside optimized packages before downstream graph analysis so `@vitejs/plugin-rsc` no longer sees the issue-845 client-boundary shape - add both a targeted transform regression and an App Router production-build regression covering the `antd` repro path ## Validation - `./node_modules/.bin/vp test run tests/optimize-imports.test.ts -t "multi-hop antd barrel"` - `./node_modules/.bin/vp test run tests/optimize-imports-build.test.ts` ## Issue Fixes #845. ## Current solution The bug happened because `vinext:optimize-imports` used to stop at an intermediate local barrel (`antd/es/button/index.js`). That file is a `"use client"` boundary with `export *`, so `@vitejs/plugin-rsc` later failed with `unsupported ExportAllDeclaration`. The fix keeps the rewrite generic rather than `antd`-specific: - recursively resolve local re-exports until the concrete implementation file is reached - safely flatten local wildcard re-exports inside optimized packages before plugin-rsc inspects them - fall back to a conservative direct-export map when parsing a JSX-bearing `.js` leaf fails, so the local-barrel walk can still reach the leaf module This means the app import now rewrites to the concrete leaf module instead of leaking the intermediate `export *` barrel into the RSC build. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#895
No description provided.