Skip to content

Commit

Permalink
Add @csstools/postcss-global-data dependency.
Browse files Browse the repository at this point in the history
The recent update to PostCSS and postcss-custom-media appears to have
broken the latter, causing custom CSS media queries to not be processed.
It's not clear exactly what changed that caused it, but it may have been
one of nested packages.

Regardless, it looks like the postcss-custom-media project's README was
updated sometime earlier this year to explicitly mention that it may not
work out of the box with CSS Modules, which we are using in this
project. They recommend using the postcss-global-data package to ensure
that the custom media definitions are available in all CSS modules.

Adding that package appears to fix the issue, allowing the pages to look
the same as before the package upgrades.
  • Loading branch information
richardxia committed Dec 5, 2023
1 parent f6883b7 commit 90f10fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const postcssGlobalData = require("@csstools/postcss-global-data");
const postcssCustomMedia = require("postcss-custom-media");

const linkResolver = require("./src/utils/linkResolver");
Expand Down Expand Up @@ -25,7 +26,15 @@ module.exports = {
{
resolve: "gatsby-plugin-postcss",
options: {
postCssPlugins: [postcssCustomMedia],
postCssPlugins: [
// This is needed to allow the custom media definitions to be
// accessible in all CSS modules. See
// https://github.com/csstools/postcss-plugins/blob/768449ddc7e226e735b9e507fd4fbd4c89c8de6c/plugins/postcss-custom-media/README.md#modular-css-processing
postcssGlobalData({
files: ["src/stylesheets/global.css"],
}),
postcssCustomMedia,
],
},
},
{
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@babel/preset-env": "^7.22.15",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.22.15",
"@csstools/postcss-global-data": "^2.1.0",
"@storybook/addon-actions": "^7.4.6",
"@storybook/addon-essentials": "^7.4.6",
"@storybook/addon-links": "^7.4.6",
Expand Down

0 comments on commit 90f10fb

Please sign in to comment.