Skip to content

Commit 0db226a

Browse files
Add Vue integration test with 1000 components (#20055)
This PR adds an integration test with Vue where we use a 1000 components and where each component references a CSS file via `@reference`. Each component has a unique class that uses `@apply`. There are some discussions in #16429 that mention that this causes OOM issues. Right now I can't reproduce that, and even with a 1000 components, it produces CSS in a reasonable time: ``` vite v7.3.3 building client environment for production... ✓ 2011 modules transformed. dist/index.html 0.23 kB │ gzip: 0.18 kB dist/assets/index-DNVNFkYQ.css 106.65 kB │ gzip: 10.79 kB dist/assets/index-B8v7EbAN.js 223.84 kB │ gzip: 49.81 kB ✓ built in 3.17s ``` I also started a Vite server and triggered file changes to see if the memory would grow forever, which it didn't. After a 1000 changes, everything still behaves smoothly: <img width="1694" height="1856" alt="image" src="https://github.com/user-attachments/assets/b16800ae-4dce-4f0d-9d97-25f4cab21c1c" /> Making changes manually to a single component, result in proper HMR request that update the browser: https://github.com/user-attachments/assets/5c79ffc6-2329-4341-9d25-82b000093e31 This test is here to make sure that it keeps working in the future. --- If I remove all `@reference` references, and usages of `@apply`, then the build time is indeed faster: ``` vite v7.3.3 building client environment for production... ✓ 2011 modules transformed. dist/index.html 0.23 kB │ gzip: 0.18 kB dist/assets/index-CcxXccJ1.css 106.61 kB │ gzip: 10.76 kB dist/assets/index-M92YFF0G.js 223.84 kB │ gzip: 49.81 kB ✓ built in 1.97s ``` So we go from `1.97s` → `3.17s`, which is a `1.2s` increase when you use `@reference` with `@apply` in 1000 files for a fresh build. I also saw some comments about the CSS growing whenever `@reference` was used, but as you can see in the snippets above they are at a stable size. ## Test plan 1. All tests still pass [ci-all] For testing on Windows / macOS --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 559f92b commit 0db226a

1 file changed

Lines changed: 106 additions & 2 deletions

File tree

integrations/vite/vue.test.ts

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { stripVTControlCharacters } from 'node:util'
2-
import { candidate, html, json, test, ts } from '../utils'
2+
import { candidate, css, html, json, test, ts } from '../utils'
33

44
test(
55
'production build',
@@ -73,6 +73,110 @@ test(
7373
},
7474
)
7575

76+
{
77+
const VUE_COMPONENT_COUNT = 1_000
78+
79+
let vueComponentsWithReferences = Object.fromEntries(
80+
Array.from({ length: VUE_COMPONENT_COUNT }, (_, idx) => [
81+
`src/components/Component${idx}.vue`,
82+
html`
83+
<template>
84+
<div class="content-['component-${idx}']">Component ${idx}</div>
85+
</template>
86+
87+
<style>
88+
@reference '../main.css';
89+
90+
.component-${idx} {
91+
@apply text-red-500;
92+
}
93+
</style>
94+
`,
95+
]),
96+
)
97+
98+
let vueComponentImports = Array.from(
99+
{ length: VUE_COMPONENT_COUNT },
100+
(_, idx) => `import Component${idx} from './components/Component${idx}.vue'`,
101+
).join('\n')
102+
103+
let vueComponentUsages = Array.from(
104+
{ length: VUE_COMPONENT_COUNT },
105+
(_, idx) => `<Component${idx} class="component-${idx}" />`,
106+
).join('\n')
107+
108+
test(
109+
'production build with many Vue style blocks referencing the main stylesheet',
110+
{
111+
fs: {
112+
'package.json': json`
113+
{
114+
"type": "module",
115+
"dependencies": {
116+
"vue": "^3.4.37",
117+
"tailwindcss": "workspace:^"
118+
},
119+
"devDependencies": {
120+
"@vitejs/plugin-vue": "^5.1.2",
121+
"@tailwindcss/vite": "workspace:^",
122+
"vite": "^7"
123+
}
124+
}
125+
`,
126+
'vite.config.ts': ts`
127+
import { defineConfig } from 'vite'
128+
import vue from '@vitejs/plugin-vue'
129+
import tailwindcss from '@tailwindcss/vite'
130+
131+
export default defineConfig({
132+
plugins: [vue(), tailwindcss()],
133+
})
134+
`,
135+
'index.html': html`
136+
<!doctype html>
137+
<html>
138+
<body>
139+
<div id="app"></div>
140+
<script type="module" src="./src/main.ts"></script>
141+
</body>
142+
</html>
143+
`,
144+
'src/main.css': css`@import 'tailwindcss';`,
145+
'src/main.ts': ts`
146+
import { createApp } from 'vue'
147+
import './main.css'
148+
import App from './App.vue'
149+
150+
createApp(App).mount('#app')
151+
`,
152+
'src/App.vue': html`
153+
<script setup>
154+
${vueComponentImports}
155+
</script>
156+
157+
<template>${vueComponentUsages}</template>
158+
`,
159+
...vueComponentsWithReferences,
160+
},
161+
},
162+
async ({ fs, exec, expect }) => {
163+
await exec('pnpm vite build')
164+
165+
let files = await fs.glob('dist/**/*.css')
166+
expect(files).toHaveLength(1)
167+
168+
await fs.expectFileToContain(files[0][0], [
169+
candidate`content-['component-0']`,
170+
candidate`component-0`,
171+
candidate`content-['component-99']`,
172+
candidate`component-99`,
173+
candidate`content-['component-999']`,
174+
candidate`component-999`,
175+
])
176+
},
177+
)
178+
}
179+
76180
test(
77181
'error when using `@apply` without `@reference`',
78182
{
@@ -132,7 +236,7 @@ test(
132236
expect.assertions(1)
133237

134238
try {
135-
await exec('pnpm vite build')
239+
await exec('pnpm vite build', {}, { ignoreStdErr: true })
136240
} catch (error) {
137241
let [, message] =
138242
/error during build:([\s\S]*?)file:/g.exec(

0 commit comments

Comments
 (0)