Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_turbo_compact_loader_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/next-plugin/package.json": "Patch"
},
"note": "Pass the Turbopack loaders only what coordinator mode reads (the port file, the theme files and, for the CSS loader, watch), plus a short key of the setup state that re-runs them when it changes. Next serializes the resolved config into .next/required-server-files.{js,json}, which ships with the app; it no longer carries the default sheet, class map, file map, theme or file paths. CSS and JavaScript output is unchanged.",
"date": "2026-11-19T00:00:00.000Z"
}
1 change: 1 addition & 0 deletions apps/landing/src/app/(detail)/docs/limitations/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ A dynamic value such as `width` becomes a CSS variable set in `style`, so a comp
- Inside `<ClassNames>`, `cx(getClass())` is a build error; put the result in a variable first, which then joins as a class.
- `withComponent` takes a tag name or a component written as a name or `a.b`. On a component made with Devup UI's or styled-components' `styled`, a target only the runtime knows, as `withComponent(make())`, is a build error: such a component compiles to a plain function with no `withComponent`. Pass the target directly, or render with `as`. A component made with Emotion's `styled` takes `withComponent` at runtime as well, so any one target works there. Options passed beside the target are a build error.
- An `.mdx` file is extracted after your MDX plugin compiles it to JavaScript, never as raw MDX. The Vite (`@mdx-js/rollup`), webpack and Rsbuild (`@mdx-js/loader`, `@rsbuild/plugin-mdx`) plugins and Next.js with webpack (`@next/mdx`) run their MDX step in a later phase: Vite in a `post` transform, webpack and Rsbuild in a `post` loader. Next.js with Turbopack (`@next/mdx`) extracts the compiled document: `@next/mdx` renames its output to `.tsx` and Turbopack runs the source rule on it again, so it works whichever of `withMDX` and `DevupUI` wraps the other. A production Turbopack build cannot extract a document before it compiles, so its stylesheet waits for the MDX route files (when `pageExtensions` lists `mdx`) and the documents they and the compiled sources import by a relative path; a document imported only through a path alias is not waited for. The Bun plugin does not extract MDX yet. The scan that reserves class names before a build reads JavaScript and TypeScript modules only, so a document's own classes are named when it compiles. Put components that need Devup UI styles in a `.tsx` module and use them from the document.
- With Turbopack, Next.js copies its resolved config into `.next/required-server-files.{js,json}` and the standalone `server.js`, so the two Devup UI loader rules (about 500 bytes, the same for any app size, with no local path) ship with the server output. They cannot be removed safely today: Next.js copies the config before any hook the plugin can register runs, and its only option that leaves bundler settings out of that copy also changes how the server reads its deployment id ([vercel/next.js#102045](https://github.com/vercel/next.js/discussions/102045)). Webpack builds add nothing there.
- The plugins read `jsxImportSource` from the `tsconfig.json` (or `jsconfig.json`) in the working directory. Opt out with `importAliases: { '@emotion/react/jsx-runtime': false }`.
- The outermost `ThemeProvider` also declares its theme on `:root`, in a `<style>` element rendered before its `<div>`, so `createGlobalStyle` and `<Global>` rules on `html`, `body` or `:root` read it; a nested provider changes only its own subtree. Several outermost providers side by side all write `:root`, and the last one in the document wins there. The `<style>` element also counts in the `textContent` of what holds the provider.
- The Bun plugin compiles `.ts`, `.mts`, `.cts`, `.tsx`, `.jsx`, `.mjs`, `.js` and `.cjs` files, ES modules and CommonJS alike, under the runtime as in `Bun.build`; `require()` and `import` keep the exports of a CommonJS module. Inside `node_modules` it compiles the `.js` and `.cjs` files of `@devup-ui` packages and of the packages listed in its `include` option only. A Bun runtime plugin must return the source of every file it matches, and Bun runs that source as an ES module, so under the runtime the plugin runs a CommonJS module itself and hands Bun an ES module that exports its `module.exports`.
Expand Down
13 changes: 11 additions & 2 deletions packages/next-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,17 @@ custom `distDir`) to `include`.
The build-time compiler defaults to `native` for Webpack and Turbopack. Select
WASM explicitly with `DevupUI(nextConfig, { engine: 'wasm' })`. The chosen engine
is retained by configuration, prewarm, extraction, CSS and delayed callbacks.
Turbopack loader options carry only the engine string; the coordinator retains
the selected physical compiler. Turbopack apps in one process keep one
Every Turbopack loader asks the coordinator, which retains the selected physical
compiler, so the loader options carry only the coordinator port file, the theme
files (relative to the project root) and a short key of the setup state.

Next.js copies its resolved config, these two loader rules included, into
`.next/required-server-files.{js,json}` and the standalone `server.js`. The
rules add about 500 bytes there, the same for any app size, with no local path.
They cannot be removed safely today: Next.js copies the config before any hook
the plugin can register runs, and its only option that leaves bundler settings
out of that copy also changes how the server reads its deployment id
([vercel/next.js#102045](https://github.com/vercel/next.js/discussions/102045)). Turbopack apps in one process keep one
coordinator and one engine session per resolved `distDir`, so their numbering,
sheet, theme and settings stay apart; give each app its own `distDir`. A config
re-evaluation of the same app replaces only that app's coordinator. Independent
Expand Down
8 changes: 5 additions & 3 deletions packages/next-plugin/src/__tests__/css-loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'node:fs'
import * as http from 'node:http'
import * as path from 'node:path'

import * as wasm from '@devup-ui/wasm'
import {
Expand Down Expand Up @@ -197,7 +198,8 @@ describe('devupUICssLoader', () => {
...defaultOptions,
watch: true,
coordinatorPortFile: portFile,
themeFiles: ['/project/devup.json', '/project/app.css'],
// Relative to the project root, as the plugin passes them
themeFiles: ['devup.json', 'app.css'],
}),
resourcePath: 'devup-ui-1.css',
} as unknown as CssLoaderThis)(
Expand All @@ -210,8 +212,8 @@ describe('devupUICssLoader', () => {
expect(result).toBe('.a{color:red}')
// A theme edit re-fetches the sheet with its new variables.
expect(addDependency.mock.calls).toEqual([
['/project/devup.json'],
['/project/app.css'],
[path.resolve('devup.json')],
[path.resolve('app.css')],
])

// NO WASM functions should be called
Expand Down
3 changes: 2 additions & 1 deletion packages/next-plugin/src/__tests__/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ export const a = <div css={{ color: 'red' }} />`
watch: true,
singleCss: true,
coordinatorPortFile: 'coordinator.port',
themeFiles: [resolve('devup.json'), resolve('base.json')],
// One relative to the project root, as the plugin passes it
themeFiles: ['devup.json', resolve('base.json')],
}),
async: mock().mockReturnValue(asyncCallback),
resourcePath: join(process.cwd(), 'src', 'App.tsx'),
Expand Down
193 changes: 46 additions & 147 deletions packages/next-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,25 +809,10 @@ describe('DevupUINextPlugin', () => {
{
loader: '@devup-ui/next-plugin/css-loader',
options: {
engine: 'native',
watch: false,
coordinatorPortFile: join('df', 'coordinator.port'),
sheetFile: join('df', 'sheet.json'),
classMapFile: join('df', 'classMap.json'),
fileMapFile: join('df', 'fileMap.json'),
themeFile: 'devup.json',
themeFiles: [resolve('devup.json')],
theme: {},
defaultClassMap: {},
defaultFileMap: {},
defaultSheet: {
css: {},
font_faces: {},
global_css_files: [],
imports: {},
keyframes: {},
properties: {},
},
themeFiles: ['devup.json'],
watch: false,
stateKey: expect.stringMatching(/^[0-9a-f]{16}$/),
},
},
],
Expand All @@ -836,36 +821,9 @@ describe('DevupUINextPlugin', () => {
{
loader: '@devup-ui/next-plugin/loader',
options: {
engine: 'native',
package: '@devup-ui/react',
cssDir: resolve('df', 'devup-ui'),
coordinatorPortFile: join('df', 'coordinator.port'),
sheetFile: join('df', 'sheet.json'),
classMapFile: join('df', 'classMap.json'),
fileMapFile: join('df', 'fileMap.json'),
themeFile: 'devup.json',
themeFiles: [resolve('devup.json')],
watch: false,
singleCss: false,
theme: {},
defaultClassMap: {},
defaultFileMap: {},
importAliases: {
'@emotion/react': null,
'@emotion/styled': 'styled',
'@emotion/css': null,
'@vanilla-extract/css': null,
'@vanilla-extract/css-utils': null,
'styled-components': 'styled',
},
defaultSheet: {
css: {},
font_faces: {},
global_css_files: [],
imports: {},
keyframes: {},
properties: {},
},
themeFiles: ['devup.json'],
stateKey: expect.stringMatching(/^[0-9a-f]{16}$/),
},
},
],
Expand Down Expand Up @@ -895,25 +853,10 @@ describe('DevupUINextPlugin', () => {
{
loader: '@devup-ui/next-plugin/css-loader',
options: {
engine: 'native',
watch: false,
coordinatorPortFile: join('df', 'coordinator.port'),
sheetFile: join('df', 'sheet.json'),
classMapFile: join('df', 'classMap.json'),
fileMapFile: join('df', 'fileMap.json'),
themeFile: 'devup.json',
themeFiles: [resolve('devup.json')],
theme: {},
defaultClassMap: {},
defaultFileMap: {},
defaultSheet: {
css: {},
font_faces: {},
global_css_files: [],
imports: {},
keyframes: {},
properties: {},
},
themeFiles: ['devup.json'],
watch: false,
stateKey: expect.stringMatching(/^[0-9a-f]{16}$/),
},
},
],
Expand All @@ -929,36 +872,9 @@ describe('DevupUINextPlugin', () => {
{
loader: '@devup-ui/next-plugin/loader',
options: {
engine: 'native',
package: '@devup-ui/react',
cssDir: resolve('df', 'devup-ui'),
coordinatorPortFile: join('df', 'coordinator.port'),
sheetFile: join('df', 'sheet.json'),
classMapFile: join('df', 'classMap.json'),
fileMapFile: join('df', 'fileMap.json'),
importAliases: {
'@emotion/react': null,
'@emotion/styled': 'styled',
'@emotion/css': null,
'@vanilla-extract/css': null,
'@vanilla-extract/css-utils': null,
'styled-components': 'styled',
},
watch: false,
singleCss: false,
theme: {},
defaultClassMap: {},
defaultFileMap: {},
defaultSheet: {
css: {},
font_faces: {},
global_css_files: [],
imports: {},
keyframes: {},
properties: {},
},
themeFile: 'devup.json',
themeFiles: [resolve('devup.json')],
themeFiles: ['devup.json'],
stateKey: expect.stringMatching(/^[0-9a-f]{16}$/),
},
},
],
Expand Down Expand Up @@ -989,25 +905,10 @@ describe('DevupUINextPlugin', () => {
{
loader: '@devup-ui/next-plugin/css-loader',
options: {
engine: 'native',
watch: false,
coordinatorPortFile: join('df', 'coordinator.port'),
sheetFile: join('df', 'sheet.json'),
classMapFile: join('df', 'classMap.json'),
fileMapFile: join('df', 'fileMap.json'),
themeFile: 'devup.json',
themeFiles: [resolve('devup.json')],
theme: 'theme',
defaultClassMap: {},
defaultFileMap: {},
defaultSheet: {
css: {},
font_faces: {},
global_css_files: [],
imports: {},
keyframes: {},
properties: {},
},
themeFiles: ['devup.json'],
watch: false,
stateKey: expect.stringMatching(/^[0-9a-f]{16}$/),
},
},
],
Expand All @@ -1023,36 +924,9 @@ describe('DevupUINextPlugin', () => {
{
loader: '@devup-ui/next-plugin/loader',
options: {
engine: 'native',
package: '@devup-ui/react',
cssDir: resolve('df', 'devup-ui'),
coordinatorPortFile: join('df', 'coordinator.port'),
sheetFile: join('df', 'sheet.json'),
classMapFile: join('df', 'classMap.json'),
fileMapFile: join('df', 'fileMap.json'),
watch: false,
singleCss: false,
theme: 'theme',
defaultClassMap: {},
defaultFileMap: {},
importAliases: {
'@emotion/react': null,
'@emotion/styled': 'styled',
'@emotion/css': null,
'@vanilla-extract/css': null,
'@vanilla-extract/css-utils': null,
'styled-components': 'styled',
},
defaultSheet: {
css: {},
font_faces: {},
global_css_files: [],
imports: {},
keyframes: {},
properties: {},
},
themeFile: 'devup.json',
themeFiles: [resolve('devup.json')],
themeFiles: ['devup.json'],
stateKey: expect.stringMatching(/^[0-9a-f]{16}$/),
},
},
],
Expand Down Expand Up @@ -1583,6 +1457,31 @@ export const box = style({ color: 'red' })`
// Verify stale port file was deleted before starting coordinator
expect(unlinkSyncSpy).toHaveBeenCalledWith(join('df', 'coordinator.port'))
})
it('keys the loaders on the setup state without shipping it in the config', () => {
process.env.TURBOPACK = '1'
existsSyncSpy.mockReturnValue(true)
mkdirSyncSpy.mockReturnValue('')
writeFileSyncSpy.mockReturnValue(undefined)
const setup = (theme: string) => {
readFileSyncSpy.mockReturnValue(JSON.stringify({ theme }))
const rules = DevupUI({}).turbopack?.rules as {
'./df/devup-ui/*.css': { options: { stateKey: string } }[]
'*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}': {
loaders: { options: { stateKey: string } }[]
}
}
const css = rules['./df/devup-ui/*.css'][0].options
const source =
rules['*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}'].loaders[0].options
expect(source.stateKey).toBe(css.stateKey)
return { rules, stateKey: source.stateKey }
}

const first = setup('first')
expect(JSON.stringify(first.rules)).not.toContain('first')
expect(setup('first').stateKey).toBe(first.stateKey)
expect(setup('second').stateKey).not.toBe(first.stateKey)
})
it('writes its own state next to another live process on the same distDir', () => {
process.env.TURBOPACK = '1'
const stateDir = join('df', `state.${process.pid}`)
Expand Down Expand Up @@ -1627,10 +1526,10 @@ export const box = style({ color: 'red' })`
const rule = config.turbopack?.rules?.[
'*.{tsx,ts,mts,cts,jsx,js,mjs,cjs}'
] as {
loaders: { options: { sheetFile: string } }[]
loaders: { options: { coordinatorPortFile: string } }[]
}
expect(rule.loaders[0].options.sheetFile).toBe(
join(stateDir, 'sheet.json'),
expect(rule.loaders[0].options.coordinatorPortFile).toBe(
join('df', `coordinator.${process.pid}.port`),
)
} finally {
portSpy.mockRestore()
Expand Down Expand Up @@ -1765,9 +1664,9 @@ export const box = style({ color: 'red' })`
loaders: { options: { themeFiles: string[] } }[]
}
expect(rule.loaders[0].options.themeFiles).toEqual([
resolve('devup.json'),
resolve('app.css'),
resolve('tokens.css'),
'devup.json',
'app.css',
'tokens.css',
])
} finally {
tailwindSpy.mockRestore()
Expand Down
Loading
Loading