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
8 changes: 8 additions & 0 deletions .changepacks/changepack_log_prepass_runtime_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"changes": {
"packages/plugin-utils/package.json": "Patch",
"packages/next-plugin/package.json": "Patch"
},
"note": "Skip `@devup-ui/react` in the passes that run before the bundler: the shared class-slot reservation and the Next production prewarm no longer read, resolve or extract the runtime package's own modules, which hold no styles. Next's Turbopack setup drops from about 40 ms to 15 ms on the benchmark app and each webpack compiler does less work. Webpack per-file builds now number a project's files without the runtime package's modules in front of them, so per-file class prefixes and stylesheet names can be shorter (`devup-ui-0.css` and `a-` instead of `devup-ui-23.css` and `x-`); the styles are unchanged.",
"date": "2026-11-19T00:00:00.000Z"
}
30 changes: 30 additions & 0 deletions packages/next-plugin/src/__tests__/prewarm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ describe('collectProductionPrewarmFiles', () => {
])
})

it('neither reads nor lists the runtime package, from the app or from another Devup UI package', () => {
// Given the runtime package and a component package importing it.
writePackage('@devup-ui/react', './index.js', {
'index.js': 'export { Box } from "./Box.js"',
'Box.js': 'export const Box = 1',
'stylex.js': 'export const props = 1',
})
writePackage('@devup-ui/components', './index.js', {
'index.js':
'import { Box } from "@devup-ui/react"; import "@devup-ui/react/stylex.js"; export const Button = Box',
})
// When collecting the extraction set of an app importing both.
const files = collectProductionPrewarmFiles({
cwd,
graph: makeGraph(
[],
[
'@devup-ui/react',
'@devup-ui/react/stylex.js',
'@devup-ui/components',
],
),
expectedBaseFiles: [],
libPackage: '@devup-ui/react',
include: [],
})
// Then only the component package is extracted ahead of the bundler.
expect(files).toEqual(['node_modules/@devup-ui/components/index.js'])
})

it('propagates a genuine accepted-package collection error', () => {
// Given a malformed accepted package manifest.
writePackage('design-system', './index.js', { 'index.js': '' })
Expand Down
2 changes: 2 additions & 0 deletions packages/next-plugin/src/prewarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { extname, isAbsolute, relative, resolve } from 'node:path'

import {
createModuleResolver,
isRuntimePackage,
parseImports,
SOURCE_FILE_REGEX,
type StaticImportGraph,
Expand Down Expand Up @@ -88,6 +89,7 @@ export function collectProductionPrewarmFiles({
[...specifiers].sort().map((specifier) => ({ importer, specifier })),
)
for (const { importer, specifier } of queue) {
if (isRuntimePackage(specifier)) continue
const local = specifier.startsWith('.') || isAbsolute(specifier)
if (!local) {
const packageName = packageNameFromSpecifier(specifier)
Expand Down
32 changes: 32 additions & 0 deletions packages/plugin-utils/src/__tests__/reservation-entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,35 @@ it("stops at a dependency the loaders leave to the bundler, but crawls Devup UI'
])
expect(dependencies).toHaveLength(6)
})

it('never reads the runtime package, from the app or from another Devup UI package', () => {
// Given
using fs = fixture()
fs.write(
'src/A.tsx',
`${STYLE}\nimport '@devup-ui/components'; import '@devup-ui/react/stylex'`,
)
fs.write('node_modules/@devup-ui/react/package.json', '{"main":"index.js"}')
fs.write('node_modules/@devup-ui/react/index.js', STYLE)
fs.write('node_modules/@devup-ui/react/stylex.js', STYLE)
fs.write(
'node_modules/@devup-ui/components/package.json',
'{"main":"index.js"}',
)
fs.write('node_modules/@devup-ui/components/index.js', STYLE)
// When
const { inputs, dependencies, packageManifests } = collectReservationInputs({
roots: ['src'],
cwd: fs.root,
package: '@devup-ui/react',
importAliases: {},
toId: (path: string) => relative(fs.root, path),
})
// Then
expect(inputs.map(({ filename }) => filename.replaceAll('\\', '/'))).toEqual([
'node_modules/@devup-ui/components/index.js',
'src/A.tsx',
])
expect(dependencies).toHaveLength(2)
expect(packageManifests).toHaveLength(1)
})
52 changes: 52 additions & 0 deletions packages/plugin-utils/src/__tests__/runtime-package.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { readdirSync, readFileSync } from 'node:fs'
import { join, relative } from 'node:path'

import { expect, it } from 'bun:test'

import { RUNTIME_PACKAGE } from '../runtime-package'
import { mergeImportAliases } from '../types'

const wasm = await import('../../../../bindings/devup-ui-wasm/pkg/index.js')

const ROOT = join(import.meta.dir, '../../../..')

function modules(directory: string): string[] {
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
const path = join(directory, entry.name)
if (entry.isDirectory())
return entry.name === '__tests__' ? [] : modules(path)
return /\.tsx?$/.test(entry.name) &&
!/\.(?:test(?:-d)?\.tsx?|d\.ts)$/.test(entry.name)
? [path]
: []
})
}

it('gets no styles from the modules of the runtime package, which the prepasses skip', () => {
// The prepasses that complete the sheet before the bundler runs neither read
// nor extract the runtime package: that is only right while it has no styles
wasm.resetBuildState()
const files = modules(join(ROOT, 'packages/react/src'))
expect(files.length).toBeGreaterThan(10)
const styled = files.filter((path) => {
const output = wasm.codeExtractWithoutSourceMap(
relative(ROOT, path).replaceAll('\\', '/'),
readFileSync(path, 'utf-8'),
RUNTIME_PACKAGE,
'./df',
// One sheet: every style any module adds shows in it
true,
false,
true,
mergeImportAliases(undefined, undefined),
)
try {
return output.updatedBaseStyle
} finally {
output.free()
}
})
expect(styled).toEqual([])
expect(wasm.getCss(null, false)).toBe('')
wasm.resetBuildState()
})
1 change: 1 addition & 0 deletions packages/plugin-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export {
type ReservationInventory,
} from './reservation-discovery'
export { reservationGraph } from './reservation-graph'
export { isRuntimePackage, RUNTIME_PACKAGE } from './runtime-package'
export {
createNodeModulesExcludeRegex,
createThemeInterfaceArgs,
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-utils/src/reservation-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isReservationReadFailure,
reservationSource,
} from './reservation-source'
import { isRuntimePackage } from './runtime-package'
import { createNodeModulesExcludeRegex } from './shared'
import type { WasmImportAliases } from './types'

Expand Down Expand Up @@ -177,6 +178,7 @@ export function collectReservationInputs(
overlay?.filename ?? physicalPath,
code,
)) {
if (isRuntimePackage(specifier)) continue
const allowed = allowedPackage(specifier, include)
const module = reservationSource(
() => resolver(specifier, physicalPath),
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin-utils/src/runtime-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* The package whose API the extraction compiles away. Its own modules hold no
* styles (extracting any of them changes nothing), so the passes that complete
* the sheet before the bundler runs neither read nor extract them.
*/
export const RUNTIME_PACKAGE = '@devup-ui/react'

/** Whether an import specifier names the runtime package or one of its subpaths */
export function isRuntimePackage(specifier: string): boolean {
return (
specifier === RUNTIME_PACKAGE || specifier.startsWith(`${RUNTIME_PACKAGE}/`)
)
}
Loading