Skip to content

Commit

Permalink
docs: add CSS bundle tree-shaking issue warnings (#5307)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Jan 30, 2023
1 parent 05228e4 commit 44c7b32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/guides/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ NOTE: You may run into hydration warnings when using Styled Components. Hopefull

<docs-warning>CSS bundling features are unstable and currently only available behind feature flags. We're confident in the use cases they solve but the API and implementation may change in the future.</docs-warning>

<docs-warning>When using CSS bundling features, you should avoid using `export *` due to an [issue with esbuild's CSS tree shaking][esbuild-css-tree-shaking-issue].</docs-warning>

Many common approaches to CSS within the React community are only possible when bundling CSS, meaning that the CSS files you write during development are collected into a separate bundle as part of the build process.

When using CSS bundling features, the Remix compiler will generate a single CSS file containing all bundled styles in your application. Note that any [regular stylesheet imports][regular-stylesheet-imports] will remain as separate files.
Expand Down Expand Up @@ -943,9 +945,10 @@ module.exports = {
[styled-components-issue]: https://github.com/styled-components/styled-components/issues/3660
[tailwind]: https://tailwindcss.com
[tailwind-intelli-sense-extension]: https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss
[esbuild-css-tree-shaking-issue]: https://github.com/evanw/esbuild/issues/1370
[css modules]: https://github.com/css-modules/css-modules
[regular-stylesheet-imports]: #regular-stylesheets
[server-dependencies-to-bundle]: ../file-conventions/remix-config#serverdependenciestobundle
[css-bundling]: #css-bundling
[vanilla-extract]: https://vanilla-extract.style
[sprinkles]: https://vanilla-extract.style/documentation/packages/sprinkles
[sprinkles]: https://vanilla-extract.style/documentation/packages/sprinkles
15 changes: 15 additions & 0 deletions docs/pages/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,19 @@ This is a hydration warning from React, and is most likely due to one of your br

Check out the page in incognito mode, the warning should disappear.

## CSS bundle being incorrectly tree-shaken

When using [CSS bundling features][css-bundling] in combination with `export *` (e.g. when using an index file like `components/index.ts` that re-exports from all sub-directories) you may find that styles from the re-exported modules are missing from the build output.

This is due to an [issue with esbuild's CSS tree shaking][esbuild-css-tree-shaking-issue]. As a workaround, you should use named re-exports instead.

```diff
-export * from "./Button";
+export { Button } from "./Button";
```

Note that, even if this issue didn't exist, we'd still recommend using named re-exports! While it may introduce a bit more boilerplate, you get explicit control over the module's public interface rather than inadvertently exposing everything.

[remix-upload-handlers-like-unstable-create-file-upload-handler-and-unstable-create-memory-upload-handler]: ../utils/parse-multipart-form-data#uploadhandler
[css-bundling]: ../guides/styling#css-bundling
[esbuild-css-tree-shaking-issue]: https://github.com/evanw/esbuild/issues/1370

0 comments on commit 44c7b32

Please # to comment.