Server components
The package in server components
Kit components can be imported straight into a server component of the Next.js App
Router — you do not need to wrap them in your own file with "use client": the directive sits
in the package itself, file by file.
But the consumer's config needs one more line:
// next.config.mjs
export default { experimental: { optimizePackageImports: ["@olddevs/ui"] } };It is required in exactly the same sense as @source for Tailwind: without it
the build passes, but the result is unusable. Measured on a Next.js 15.5 app
(First Load JS, package installed from a tarball):
| What the page imports | Without the line | With the line |
|---|---|---|
| nothing from the kit (baseline) | 102 kB | 103 kB |
AddIcon from @olddevs/ui/icons | 103 kB | 103 kB |
one Button from the root | 408 kB | 114 kB |
cn and tableStateToParams | 408 kB | 103 kB |
Read the third row like this: importing a single button brought the user the whole kit. The fourth: a server component that needs two pure functions and no components shipped the same 306 kB of client code.
The cause is not how the package is built but the boundary of the client graph: the root
entry point re-exports about a hundred client modules, and tree shaking does not work across that
boundary. optimizePackageImports rewrites the import from the
root entry point into a set of targeted ones, and the cost drops back to something reasonable. Details in
ADR-0029.
The Editor subpath needs its own line. The @olddevs/ui/editor entry point is the same
kind of barrel: next to the server-side RichTextView it re-exports the client
RichTextEditor. The root line does not cover the subpath, and a page that needs only a Document
View ships the whole Editor together with the engine:
// next.config.mjs — if you import @olddevs/ui/editor
export default {
experimental: { optimizePackageImports: ["@olddevs/ui", "@olddevs/ui/editor"] },
};Measured on a consumer fixture (RichTextView with a code Block in a server
component): 435 kB of First Load JS without the second line and 137 kB with it — only
the Island of the "Copy" button goes to the client. The @olddevs/ui/editor/schema
and @olddevs/ui/editor/highlight entry points are not barrels and contain no client modules,
so they do not need the line.
Utilities (cn, tableStateToParams, formatMask and the rest of
api/utilities.md) are server-safe: they do not
import React and do not pull anything into the client graph. The package has no separate entry point such as
@olddevs/ui/server and none is planned — with the line above it is
not needed.