question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blur filters don't work in production build

See original GitHub issue

What version of Tailwind CSS are you using?

2.1.4

What build tool (or framework if it abstracts the build tool) are you using?

laravel mix 6.0.19

What version of Node.js are you using?

16.0.0

What browser are you using?

Chrome

What operating system are you using?

maxOS

Reproduction repository

https://github.com/denjaland/tailwind-bug-repro

Describe your issue

We have a div that has applied styles filter blur-3xl Renders quite beautifully on a dev build, but on the production build we have a hideous result:

Dev result: image

Production result: image

Not really what we are looking for. So I checked the compiled CSS, and this is what I see.

On dev build, I have these styles:

.filter {
    filter: var(--tw-filter);
}
.blur-3xl {
    --tw-blur: blur(64px);
    filter: var(--tw-filter);
}

The production build however has this as a result:

.blur-3xl, .filter {
    filter: var(--tw-filter);
}
.blur-3xl {
    --tw-blur: blur(64px);
}

which, in Chrome at least, doesn’t render correctly.

I’m not sure it’s a bug, but I wouldn’t even know where to begin checking to see what’s causing the issue if it isn’t in the compiler.

I have tested it in regular as well as jit mode with the same result.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adamwathancommented, Aug 21, 2021

Yeah GitHub repo would be perfect thank you! Can figure this out for sure 👍🏻

0reactions
bradlccommented, Aug 24, 2021

Hey @denjaland! Tailwind makes heavy use of CSS custom properties (variables), and sometimes an empty value (actually a single space) is used. While this is perfectly valid, some minifiers may handle it incorrectly and break the CSS, so we use comments to “trick” minifiers into producing working output, for example:

*, ::before, ::after {
  --tw-blur: var(--tw-empty,/*!*/ /*!*/);
  --tw-brightness: var(--tw-empty,/*!*/ /*!*/);
  --tw-contrast: var(--tw-empty,/*!*/ /*!*/);
  --tw-grayscale: var(--tw-empty,/*!*/ /*!*/);
  --tw-hue-rotate: var(--tw-empty,/*!*/ /*!*/);
  --tw-invert: var(--tw-empty,/*!*/ /*!*/);
  --tw-saturate: var(--tw-empty,/*!*/ /*!*/);
  --tw-sepia: var(--tw-empty,/*!*/ /*!*/);
  --tw-drop-shadow: var(--tw-empty,/*!*/ /*!*/);
  --tw-filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
}

Now the problem you are running into is happening because you are using Mix’s minify(), which uses clean-css under the hood. Unfortunately, even with our “tricks” clean-css seems to be producing broken output.

Fortunately in this case there is a simple fix, which is to remove minify() completely, since postCss() minifies its output in production anyway. This minification uses cssnano which handles the empty values just fine. Here’s a pull request with the changes required to fix your reproduction: https://github.com/denjaland/tailwind-bug-repro/pull/1

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backdrop filter not working after build #7044 - GitHub
After building, the backdrop filter blur isn't working, but the css is there. Not tested with other filters.
Read more >
Why blur filter does not work in this example - Stack Overflow
Blur actually blurs content inside that object. It doesn't blur everything beneath the div. For example, if you add the image inside of...
Read more >
Tips for Using the Blur Filters in Photoshop
Photoshop's blur filters handy for creating blur in post-production to add a shallow depth of field and other effects. Here are some tips...
Read more >
Photoshop Elements Blur filters - Adobe Support
The Surface Blur filter blurs an image while preserving edges. This filter is useful for creating special effects and for removing noise and ......
Read more >
overflow hidden doesn't work anymore when blur is applied
I've attempted to make a reproduction for this issue, with little success. The closest I could come is that a blur filter itself...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found