Currently, I am working on a React component that adjusts opacity values based on the support for the CSS backdrop-filter
directive:
background={(() => {
const opacity = isBackdropFilterSupported() ? 0.75 : 0.98
return (
`linear-gradient(
180deg, rgba(76, 63, 143, ${opacity}) 62.76%,
rgba(184, 169, 255, ${opacity}) 100%
)`
)
})()}
The challenge arises when the site is server-side rendered with Next.js. The server generates
false
as the value returned by
CSS.supports('backdrop-filter', 'blur(1px)')
, leading to inconsistencies regardless of client properties.
To address this issue, one potential solution involves utilizing CSS in the following manner:
.drawer {
--opacity: 0.75;
background: linear-gradient(
180deg, rgba(76, 63, 143, var(--opacity)) 62.76%,
rgba(184, 169, 255, var(--opacity)) 100%
);
}
@supports not (backdrop-filter: blur(1px)) {
.drawer { --opacity: 0.98; }
}
This approach aims to circumvent the server-side rendering issue and be interpreted correctly by the client. However, integrating such styles into Chakra-UI, which this project is built upon, poses a challenge due to the lack of guidance on how to do so.