Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent order of CSS rules between dev and build #39076

Open
2 tasks done
receter opened this issue Sep 3, 2024 · 1 comment
Open
2 tasks done

Inconsistent order of CSS rules between dev and build #39076

receter opened this issue Sep 3, 2024 · 1 comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@receter
Copy link

receter commented Sep 3, 2024

Preliminary Checks

Description

When I run gatsby develop the order of CSS classes is as expected. When building the CSS order appears to be different in some cases.

I expect that CSS Module files that are imported earlier will appear before classes from CSS Module files that are imported later.

In my reproduction example this is not the case after building. One CSS class that is imported late, appears too early in the CSS.

If you run npm run start you will see this:

dev

If you run npm run build && npx serve public you will see this instead:

build

This might be related to a CSS Module file that is imported inside an example component library package in node_modules.

Reproduction Link

https://github.com/receter/gatsby-css-order-issue

Steps to Reproduce

Clone https://github.com/receter/gatsby-css-order-issue
Run dev server: The text is blue
Build and serve: The text is black

Expected Result

The text should be blue

Actual Result

The text is black when built

Environment

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
    npm: 10.8.3 - ~/.nvm/versions/node/v18.20.4/bin/npm
  Languages:
    Python: 3.11.4 - /opt/homebrew/opt/python@3.11/libexec/bin/python
  Browsers:
    Chrome: 128.0.6613.114
    Safari: 17.6
  npmPackages:
    gatsby: ^5.13.7 => 5.13.7
    gatsby-cli: ^5.13.3 => 5.13.3
    gatsby-css-order-issue-package: ^1.0.0 => 1.0.0
  npmGlobalPackages:
    gatsby-css-order-issue-package: 1.0.0

Config Flags

No response

@receter receter added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 3, 2024
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 3, 2024
@receter
Copy link
Author

receter commented Sep 4, 2024

I just found out that removing side effects in the external package's package.json does fix this issue. And I think (but I am not 100% sure) that in case of importing CSS Modules (like import * as styles from "x.module.css"), marking them as side effects is not necessary.

  "sideEffects": [
    "**/*.css"
  ],

But the issue still kind of persists if I switch from using CSS Modules to normal CSS because in this case I think I should not remove the side effect marking from the package.json.

Having said that removing sideEffects will also fix the issue here because the bundler well not tree shake the module if sideEffects is not defined in package.json.

This might be related:

webpack-contrib/mini-css-extract-plugin#1070
webpack/webpack#7094

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant