Generated CSS that creates warnings can cause infinite loops in generateCodeFrame
#15076
Closed
7 tasks done
Labels
p4-important
Violate documented behavior or significantly improves performance (priority)
Describe the bug
This took me the better part of two days to pin down enough to make what I'd call a minimal reproduction, though you might disagree with how many dependencies I dragged into this.
Renovate attempted to update Vite from 4.5.0 to 5.0.0 (for the record tried 5.0.2 too) over the weekend, and our CI pipeline on a on-prem GitLab instance dutifully attempted to build everything for a staging deployment for human evaluation. Build job fails with
ERROR: Job failed: execution took longer than 1h0m0s seconds
when we expect it to take 3 minutes best case with caching, ~8-9 minutes at absolute worst without. Since it just gets stuck with no useful errors/warnings/logs on CI (non-interactive TTY), I pull it down and try a build manually, which seems to get stuck on random files, ours or NPM packages even. And thus starts the madness of finding why.I've run debugging on Vite while running on my repo it gets stuck inside this loop here.
vite/packages/vite/src/node/utils.ts
Lines 516 to 517 in f576d98
When I was poking at it,
j
got up to something like 1.4 trillion and change (if that was index into a file, that would be around the 1.3 GB mark). Whilej <= i + range
was false, the other half of the logical or checkend > count
was always true with nothing to change it in that loop. Running a bisect, I did find a commit Git wants to blame (2b4e793, from #14984) and, from an outsiders view, I'd agree with it.Eventually, by taking a machete to a copy of our code to hack out random chunks of code/imports, I found that either removing the
@tailwind
rules and/or removing our most of our Vue components it would go away. More hacking away at the code around just TailwindCSS to try and pin it down. Turned out a custom plugin was adding a CSS property ofcolor-adjust
for a utility and it was never updated toprint-color-adjust
to stop Autoprefixer from throwing warnings (oops!).Here is where my understanding of this all breaks down. Manually generating the CSS with the rule was fine, though I'd get the expected warning from Autoprefixer. Creating a new utility function (with the plugin gone for testing) for it with a unique name also did not trigger it. Spent a good amount of time bashing my head on it, went home for the day, then came back fresh for another look. Came up with the idea to check where said utility was being used, and saw that there was a use with a variant (
print
of all things, probably because work was being put into make a given page printable but still have some useful bits of color). That was finally what I could use to create a minimal reproduction. Funnily enough, manually creating that CSS rule with the variant does not trigger it.This kinda leaves the cause to a generated rule in a media query. I've tested a few of Tailwind's variants, dark mode and responsive design also trigger it, not just
print
, buthover
,focus
,active
,first
,last
,odd
,even
,before
andafter
don't. This helps pin it more and more on media based varants, not pseudo-element or pseudo-class based ones.Hacking around while looking for answers, I tried to patch Vite locally as a test, swapping
continue
for abreak
here. Just foundgenerateCodeFrame
in the compiled copy and swapped it.vite/packages/vite/src/node/utils.ts
Lines 516 to 517 in f576d98
It does work, but i doubt that it's the proper fix. Figured it was worth mentioning as a point to dig around.
Hope this all helps with getting a fix for it. I'm just going to fix our code so I can get on with work proper, but this still should be fixed in Vite so no others get lost in this pothole.
Thanks!
Reproduction
https://stackblitz.com/edit/vitejs-vite-dnqqxn
Steps to reproduce
This is largely the same as setting up TailwindCSS with Vite like you would on a new project.
npm create vite@latest -- --template vanilla bug
cd bug
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
content
to[ "./index.html", "./src/**/*.{js,ts,jsx,tsx}"]
intailwind.config.js
src/style.css
:lg:vite-bug
to anywhere insideindex.html
or one of the included JS files insrc
. A comment works just fine for it../node_modules/.bin/vite build
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: