Skip to content

Commit 1cc01ac

Browse files
WIP
1 parent ea24995 commit 1cc01ac

File tree

2 files changed

+130
-16
lines changed

2 files changed

+130
-16
lines changed

integrations/vite/solidstart.test.ts

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { candidate, css, fetchStyles, js, json, retryAssertion, test, ts } from '../utils'
2+
3+
const WORKSPACE = {
4+
'package.json': json`
5+
{
6+
"type": "module",
7+
"dependencies": {
8+
"@solidjs/start": "^1",
9+
"solid-js": "^1",
10+
"vinxi": "^0",
11+
"@tailwindcss/vite": "workspace:^",
12+
"tailwindcss": "workspace:^"
13+
}
14+
}
15+
`,
16+
'jsconfig.json': json`
17+
{
18+
"compilerOptions": {
19+
"jsx": "preserve",
20+
"jsxImportSource": "solid-js"
21+
}
22+
}
23+
`,
24+
'app.config.js': ts`
25+
import { defineConfig } from '@solidjs/start/config'
26+
import tailwindcss from '@tailwindcss/vite'
27+
28+
export default defineConfig({
29+
vite: {
30+
plugins: [tailwindcss()],
31+
},
32+
})
33+
`,
34+
'src/entry-server.jsx': js`
35+
// @refresh reload
36+
import { createHandler, StartServer } from '@solidjs/start/server'
37+
38+
export default createHandler(() => (
39+
<StartServer
40+
document={({ assets, children, scripts }) => (
41+
<html lang="en">
42+
<head>{assets}</head>
43+
<body>
44+
<div id="app">{children}</div>
45+
{scripts}
46+
</body>
47+
</html>
48+
)}
49+
/>
50+
))
51+
`,
52+
'src/entry-client.jsx': js`
53+
// @refresh reload
54+
import { mount, StartClient } from '@solidjs/start/client'
55+
56+
mount(() => <StartClient />, document.getElementById('app'))
57+
`,
58+
'src/app.jsx': js`
59+
import './app.css'
60+
export default function App() {
61+
return <h1 class="underline">Hello world!</h1>
62+
}
63+
`,
64+
'src/app.css': css`@import 'tailwindcss';`,
65+
}
66+
67+
test(
68+
'dev mode',
69+
{
70+
fs: WORKSPACE,
71+
},
72+
async ({ fs, spawn, expect }) => {
73+
let process = await spawn('pnpm vinxi dev', {
74+
env: {
75+
TEST: 'false', // VERY IMPORTANT OTHERWISE YOU WON'T GET OUTPUT
76+
NODE_ENV: 'development',
77+
},
78+
})
79+
80+
let url = ''
81+
await process.onStdout((m) => {
82+
let match = /Local:\s*(http.*)\//.exec(m)
83+
if (match) url = match[1]
84+
return Boolean(url)
85+
})
86+
87+
await retryAssertion(async () => {
88+
let css = await fetchStyles(url)
89+
expect(css).toContain(candidate`underline`)
90+
})
91+
92+
await retryAssertion(async () => {
93+
await fs.write(
94+
'src/app.jsx',
95+
js`
96+
import './app.css'
97+
export default function App() {
98+
return <h1 class="underline font-bold">Hello world!</h1>
99+
}
100+
`,
101+
)
102+
103+
let css = await fetchStyles(url)
104+
expect(css).toContain(candidate`underline`)
105+
expect(css).toContain(candidate`font-bold`)
106+
})
107+
},
108+
)

packages/@tailwindcss-vite/src/index.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,15 @@ export default function tailwindcss(): Plugin[] {
8888
}
8989

9090
function invalidateAllRoots(isSSR: boolean) {
91-
for (let server of servers) {
92-
let updates: Update[] = []
93-
for (let [id, root] of roots.entries()) {
91+
for (let [id] of roots.entries()) {
92+
let foundRoot = false
93+
94+
for (let server of servers) {
95+
let updates: Update[] = []
9496
let module = server.moduleGraph.getModuleById(id)
95-
if (!module) {
96-
// Note: Removing this during SSR is not safe and will produce
97-
// inconsistent results based on the timing of the removal and
98-
// the order / timing of transforms.
99-
if (!isSSR) {
100-
// It is safe to remove the item here since we're iterating on a copy
101-
// of the keys.
102-
roots.delete(id)
103-
}
104-
continue
105-
}
97+
if (!module) continue
98+
99+
foundRoot = true
106100

107101
roots.get(id).requiresRebuild = false
108102
server.moduleGraph.invalidateModule(module)
@@ -112,10 +106,21 @@ export default function tailwindcss(): Plugin[] {
112106
acceptedPath: module.url,
113107
timestamp: Date.now(),
114108
})
109+
110+
if (updates.length > 0) {
111+
server.hot.send({ type: 'update', updates })
112+
}
115113
}
116114

117-
if (updates.length > 0) {
118-
server.hot.send({ type: 'update', updates })
115+
if (!foundRoot && !isSSR) {
116+
// Note: Removing this during SSR is not safe and will produce
117+
// inconsistent results based on the timing of the removal and
118+
// the order / timing of transforms.
119+
if (!isSSR) {
120+
// It is safe to remove the item here since we're iterating on a copy
121+
// of the keys.
122+
roots.delete(id)
123+
}
119124
}
120125
}
121126
}
@@ -210,6 +215,7 @@ export default function tailwindcss(): Plugin[] {
210215

211216
// Scan all non-CSS files for candidates
212217
transformIndexHtml(html, { path }) {
218+
if (!path) return
213219
scanFile(path, html, 'html', isSSR)
214220
},
215221
transform(src, id, options) {

0 commit comments

Comments
 (0)