Skip to content

feat: one import path per public component, for Turbopack builds (3.0) - #358

Merged
lorant-one merged 3 commits into
feat/3-0-breaking-cleanupfrom
feat/component-subpath-exports
Oct 30, 2026
Merged

lorant-one merged 3 commits into
feat/3-0-breaking-cleanupfrom
feat/component-subpath-exports

Conversation

@lorant-one

@lorant-one lorant-one commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Requested by Lorant · project thread

This addresses the P0 from the Graphite migration report: on Next 16, Turbopack shipped the whole library to a page that used only a few components.

Owner decision pending: this adds an entry point to the 3.0 exports contract (MIGRATING §12). The approach below is the one I recommended.

Measured on this branch

Each figure is a Next 16.2.12 static export of one page with Column, Row, Heading and Text, plus one Button. The number is the gzip JS that index.html loads; the framework alone is about 191 kB.

Build Root import Component paths
Turbopack (default) 340 kB, about 150 kB of it Once UI, DatePicker/EmojiPicker/Kbar included 217 kB (about 26 kB of Once UI)
Turbopack + optimizePackageImports 340 kB, so the setting has no effect n/a
webpack + optimizePackageImports 198 kB n/a

Setting sideEffects to only ./dist/css/*.css made no difference under Turbopack. The cause is the server compile collecting client references through the barrel.

Changes

  • exports lists ./components/<Name> one by one for the 86 modules the root barrel re-exports whole. It is not the 2.x wildcard, so internal modules (FormContext, ScrollLock's helpers…) stay private, as 3.0 intends.
  • scripts/sync-component-exports.mjs generates the list; --check reports drift.
  • component-subpaths.test.ts checks that the entries equal the barrel's modules exactly. package-exports.test.ts still forbids the wildcard and internal paths.
  • The codemod keeps a deep import of a public component on its own path and drops .js. It still moves internal modules and removed components (such as Modal) to the root.
  • Docs: the quick start, AGENTS.md, MIGRATING §12 and the CHANGELOG.

Checks

  • core vitest run passes 3896/3896, tsc --noEmit is clean, and lint:gate is at baseline.
  • The codemod tests pass 447/447, and check:package passes.

Not here

  • A CI size check under both bundlers. It would need two Next builds per run, so it should be weighed against the Actions budget first.

🤖 Generated with Claude Code

https://claude.ai/code/session_016gNJtvihFgt8bSFzr13Wsn

Next 16 builds with Turbopack, which ignores optimizePackageImports, so
a server component importing Button from the package root ships every
client component (measured: ~150 KB gzip of Once UI on a page with a
Button and four layout components). @once-ui-system/core/components/<Name>
imports one file; the same page drops to ~26 KB. Root imports unchanged.

From the Graphite migration report. Docs quick start and AGENTS.md say
when to use it; a test keeps each component file exporting its name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtvihFgt8bSFzr13Wsn
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
core-docs Ignored Ignored Preview Oct 28, 2026 10:10pm UTC

Copy link
Copy Markdown
Member Author

"Build, typecheck and test" is failing in package-exports.test.ts, and the failure is real. The 3.0 exports contract (MIGRATING.md §12, B2/B3/F9) removed ./components/* on purpose: it re-exported part of the root, and it made every file in dist/components public, internal modules included. The codemod also rewrites /components/<Name> imports to the root. So this PR reverses a decision 3.0 already made, and I didn't run the full suite before pushing, which would have caught it.

I'm not changing the contract test until the owner decides between three options:

  • (a) Bring back ./components/* and update the test, MIGRATING and the codemod.
  • (b) Add explicit, generated subpaths for public components only, so no internal modules are exposed.
  • (c) Keep root-only imports and document webpack + optimizePackageImports for apps that care about bundle size.

The Turbopack measurement in the description holds whichever option is chosen.


Generated by Claude Code

3.0 dropped the ./components/* wildcard because it made internal modules
public, and package-exports.test.ts enforces that. List an entry per
module the root barrel re-exports whole instead (86), generated by
scripts/sync-component-exports.mjs, so no context or shared style is
importable. The codemod keeps a deep import of a public component on
its own path (dropping .js) rather than moving it to the root, and still
moves internals and removed components. MIGRATING §12 and the CHANGELOG
say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtvihFgt8bSFzr13Wsn
@lorant-one lorant-one changed the title feat: one import path per component for Turbopack builds (3.0) feat: one import path per public component, for Turbopack builds (3.0) Oct 28, 2026
@lorant-one
lorant-one merged commit e207594 into feat/3-0-breaking-cleanup Oct 30, 2026
8 checks passed
@lorant-one
lorant-one deleted the feat/component-subpath-exports branch October 31, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants