Skip to content

Commit a629ea7

Browse files
github-actions[bot]thecrypticaceactions-user
authored
chore: sync with upstream (#4)
* Bump bundled Tailwind CSS version * Improve performance in large files (tailwindlabs#1507) There are two performance improvements here that both come down to caching: - We call `indexToPosition` *a lot*. Every time this is called it takes the string passed in and re-computes the indices every time. There's no need for this so we have a small, module-level LRU cache to store the data. This should eventually be replaced with parsing and storing data up front when files are edited instead of just doing this whenever we receive a request. That would negate the need for a module-level cache. - We call `compile()` and `candidatesToCss` *a lot* as well. This is expected but 90% of the time the classes passed in have already been seen. We take the generated CSS and convert to a PostCSS node because a lot of the implementation uses that internally. There's no need to go through the whole parse -> serialize -> re-parse routine like we are. I've opted to store the compiled PostCSS roots on the `designSystem.storage` object (which will be created when it doesn't exist on old versions) and we'll return clones of those objects every time (since they may get mutated). With this there's only one large-ish block in a left-heavy profile: `findClassListsInHtmlRange`. That is mostly related to the class attribute lexer. Fixing it will require us to scan document and store info about them when they change. We shouldn't need to run the class attribute lexer if the document hasn't changed. Fixing this will require some more work though. Fixes tailwindlabs#1503 --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me> Co-authored-by: GitHub Action <action@github.com>
1 parent 7601587 commit a629ea7

File tree

28 files changed

+119
-87
lines changed

28 files changed

+119
-87
lines changed

packages/tailwindcss-language-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"rimraf": "3.0.2",
9090
"stack-trace": "0.0.10",
9191
"tailwindcss": "3.4.18",
92-
"tailwindcss-v4": "npm:tailwindcss@4.1.15",
92+
"tailwindcss-v4": "npm:tailwindcss@4.1.17",
9393
"tinyglobby": "^0.2.12",
9494
"tsconfck": "^3.1.4",
9595
"tsconfig-paths": "^4.2.0",

packages/tailwindcss-language-server/src/project-locator.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ testLocator({
455455
},
456456
expected: [
457457
{
458-
version: '4.1.15 (bundled)',
458+
version: '4.1.17 (bundled)',
459459
config: '/src/a/b/c/index.css',
460460
content: [],
461461
},
@@ -487,12 +487,12 @@ testLocator({
487487
},
488488
expected: [
489489
{
490-
version: '4.1.15 (bundled)',
490+
version: '4.1.17 (bundled)',
491491
config: '/index.css',
492492
content: [],
493493
},
494494
{
495-
version: '4.1.15 (bundled)',
495+
version: '4.1.17 (bundled)',
496496
config: '/src/vendor/c.css',
497497
content: [],
498498
},
@@ -519,12 +519,12 @@ testLocator({
519519
},
520520
expected: [
521521
{
522-
version: '4.1.15 (bundled)',
522+
version: '4.1.17 (bundled)',
523523
config: '/src/app.css',
524524
content: [],
525525
},
526526
{
527-
version: '4.1.15 (bundled)',
527+
version: '4.1.17 (bundled)',
528528
config: '/a/foo.css',
529529
content: [],
530530
},
@@ -554,12 +554,12 @@ testLocator({
554554
},
555555
expected: [
556556
{
557-
version: '4.1.15 (bundled)',
557+
version: '4.1.17 (bundled)',
558558
config: '/src/app.css',
559559
content: [],
560560
},
561561
{
562-
version: '4.1.15 (bundled)',
562+
version: '4.1.17 (bundled)',
563563
config: '/a/foo.css',
564564
content: [],
565565
},
@@ -581,7 +581,7 @@ testLocator({
581581
},
582582
expected: [
583583
{
584-
version: '4.1.15 (bundled)',
584+
version: '4.1.17 (bundled)',
585585
config: '/src/app.css',
586586
content: [],
587587
},

packages/tailwindcss-language-server/src/util/v4/design-system.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { plugins } from './plugins'
1313

1414
const HAS_V4_IMPORT = /@import\s*(?:'tailwindcss'|"tailwindcss")/
1515
const HAS_V4_THEME = /@theme\s*\{/
16+
const COMPILE_CACHE = Symbol('LSP_COMPILE_CACHE')
1617

1718
export async function isMaybeV4(css: string): Promise<boolean> {
1819
// Look for:
@@ -215,6 +216,11 @@ export async function loadDesignSystem(
215216
}),
216217
})
217218

219+
// This object doesn't exist in older versions but we can patch it in so it
220+
// seems like it always existed.
221+
design.storage ??= {}
222+
design.storage[COMPILE_CACHE] = {}
223+
218224
// Step 4: Augment the design system with some additional APIs that the LSP needs
219225
Object.assign(design, {
220226
dependencies: () => dependencies,
@@ -227,25 +233,42 @@ export async function loadDesignSystem(
227233
// - Replace `candidatesToCss` with a `candidatesToAst` API
228234
// First step would be to convert to a PostCSS AST by transforming the nodes directly
229235
// Then it would be to drop the PostCSS AST representation entirely in all v4 code paths
230-
compile(classes: string[]): (postcss.Root | null)[] {
231-
let css = design.candidatesToCss(classes)
236+
compile(classes: string[]): postcss.Root[] {
237+
// 1. Compile any uncached classes
238+
let cache = design.storage[COMPILE_CACHE] as Record<string, postcss.Root>
239+
let uncached = classes.filter((name) => cache[name] === undefined)
240+
241+
let css = design.candidatesToCss(uncached)
232242
let errors: any[] = []
233243

234-
let roots = css.map((str) => {
235-
if (str === null) return postcss.root()
244+
for (let [idx, cls] of uncached.entries()) {
245+
let str = css[idx]
246+
247+
if (str === null) {
248+
cache[cls] = postcss.root()
249+
continue
250+
}
236251

237252
try {
238-
return postcss.parse(str.trimEnd())
253+
cache[cls] = postcss.parse(str.trimEnd())
239254
} catch (err) {
240255
errors.push(err)
241-
return postcss.root()
256+
cache[cls] = postcss.root()
257+
continue
242258
}
243-
})
259+
}
244260

245261
if (errors.length > 0) {
246262
console.error(JSON.stringify(errors))
247263
}
248264

265+
// 2. Pull all the classes from the cache
266+
let roots: postcss.Root[] = []
267+
268+
for (let cls of classes) {
269+
roots.push(cache[cls].clone())
270+
}
271+
249272
return roots
250273
},
251274

packages/tailwindcss-language-server/tests/colors/colors.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ defineTest({
349349

350350
expect(c.project).toMatchObject({
351351
tailwind: {
352-
version: '4.1.15',
352+
version: '4.1.17',
353353
isDefaultVersion: true,
354354
},
355355
})
@@ -388,7 +388,7 @@ defineTest({
388388

389389
expect(c.project).toMatchObject({
390390
tailwind: {
391-
version: '4.1.15',
391+
version: '4.1.17',
392392
isDefaultVersion: true,
393393
},
394394
})

packages/tailwindcss-language-server/tests/diagnostics/diagnostics.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,6 @@ defineTest({
446446
defineTest({
447447
name: 'Shows warning when using non-canonical classes',
448448
fs: {
449-
// TODO: Drop this when the embedded version of tailwindcss is v4.1.15
450-
'package.json': json`
451-
{
452-
"dependencies": {
453-
"tailwindcss": "0.0.0-insiders.249bed0"
454-
}
455-
}
456-
`,
457449
'app.css': css`
458450
@import 'tailwindcss';
459451
`,

packages/tailwindcss-language-server/tests/env/v4.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defineTest({
2121

2222
expect(await client.project()).toMatchObject({
2323
tailwind: {
24-
version: '4.1.15',
24+
version: '4.1.17',
2525
isDefaultVersion: true,
2626
},
2727
})
@@ -137,7 +137,7 @@ defineTest({
137137

138138
expect(await client.project()).toMatchObject({
139139
tailwind: {
140-
version: '4.1.15',
140+
version: '4.1.17',
141141
isDefaultVersion: true,
142142
},
143143
})
@@ -188,7 +188,7 @@ defineTest({
188188
'package.json': json`
189189
{
190190
"dependencies": {
191-
"tailwindcss": "4.1.15"
191+
"tailwindcss": "4.1.17"
192192
}
193193
}
194194
`,
@@ -205,7 +205,7 @@ defineTest({
205205

206206
expect(await client.project()).toMatchObject({
207207
tailwind: {
208-
version: '4.1.15',
208+
version: '4.1.17',
209209
isDefaultVersion: false,
210210
},
211211
})
@@ -243,7 +243,7 @@ defineTest({
243243
'package.json': json`
244244
{
245245
"dependencies": {
246-
"tailwindcss": "4.1.15"
246+
"tailwindcss": "4.1.17"
247247
}
248248
}
249249
`,
@@ -270,7 +270,7 @@ defineTest({
270270

271271
expect(await client.project()).toMatchObject({
272272
tailwind: {
273-
version: '4.1.15',
273+
version: '4.1.17',
274274
isDefaultVersion: false,
275275
},
276276
})
@@ -322,7 +322,7 @@ defineTest({
322322

323323
expect(await client.project()).toMatchObject({
324324
tailwind: {
325-
version: '4.1.15',
325+
version: '4.1.17',
326326
isDefaultVersion: true,
327327
},
328328
})
@@ -354,7 +354,7 @@ defineTest({
354354
'package.json': json`
355355
{
356356
"dependencies": {
357-
"tailwindcss": "4.1.15"
357+
"tailwindcss": "4.1.17"
358358
}
359359
}
360360
`,
@@ -831,7 +831,7 @@ defineTest({
831831

832832
expect(await client.project()).toMatchObject({
833833
tailwind: {
834-
version: '4.1.15',
834+
version: '4.1.17',
835835
isDefaultVersion: true,
836836
},
837837
})

packages/tailwindcss-language-server/tests/fixtures/v4/basic/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"tailwindcss": "4.1.15"
3+
"tailwindcss": "4.1.17"
44
}
55
}

packages/tailwindcss-language-server/tests/fixtures/v4/css-loading-js/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"tailwindcss": "4.1.15"
3+
"tailwindcss": "4.1.17"
44
}
55
}

0 commit comments

Comments
 (0)