diff --git a/.changeset/giant-kings-repair.md b/.changeset/giant-kings-repair.md new file mode 100644 index 00000000000..0afc9d0b354 --- /dev/null +++ b/.changeset/giant-kings-repair.md @@ -0,0 +1,8 @@ +--- +"@remix-run/dev": minor +"@remix-run/react": minor +"@remix-run/server-runtime": minor +"@remix-run/testing": minor +--- + +Add unstable support for [Vanilla Extract](https://vanilla-extract.style) via the `future.unstable_vanillaExtract` feature flag diff --git a/.changeset/hungry-owls-greet.md b/.changeset/hungry-owls-greet.md index 3257dafd368..a40b1fdcef3 100644 --- a/.changeset/hungry-owls-greet.md +++ b/.changeset/hungry-owls-greet.md @@ -5,4 +5,4 @@ "@remix-run/testing": minor --- -Add unstable support for CSS side-effect imports via `future.unstable_cssSideEffectImports` feature flag +Add unstable support for CSS side-effect imports via the `future.unstable_cssSideEffectImports` feature flag diff --git a/.changeset/little-avocados-fetch.md b/.changeset/little-avocados-fetch.md index a090ecb9575..b8873ce2946 100644 --- a/.changeset/little-avocados-fetch.md +++ b/.changeset/little-avocados-fetch.md @@ -6,4 +6,4 @@ "@remix-run/testing": minor --- -Add unstable support for CSS Modules via `future.unstable_cssModules` feature flag +Add unstable support for CSS Modules via the `future.unstable_cssModules` feature flag diff --git a/docs/guides/styling.md b/docs/guides/styling.md index ff57b457700..672be5f35db 100644 --- a/docs/guides/styling.md +++ b/docs/guides/styling.md @@ -772,7 +772,7 @@ NOTE: You may run into hydration warnings when using Styled Components. Hopefull 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-2] will remain as separate files. +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. Unlike many other tools in the React ecosystem, we do not insert the CSS bundle into the page automatically. Instead, we ensure that you always have control over the link tags on your page. This lets you decide where the CSS file is loaded relative to other stylesheets in your app. @@ -790,7 +790,7 @@ import { cssBundleHref } from "@remix-run/css-bundle"; export const links: LinksFunction = () => { return [ - { rel: "stylesheet", href: cssBundleHref }, + ...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []), // ... ]; }; @@ -843,6 +843,61 @@ export const Button = React.forwardRef( Button.displayName = "Button"; ``` +### Vanilla Extract + +This feature is unstable and currently only available behind a feature flag. We're confident in the use cases it solves but the API and implementation may change in the future. + +[Vanilla Extract][vanilla-extract] is a zero-runtime CSS-in-TypeScript (or JavaScript) library that lets you use TypeScript as your CSS preprocessor. Styles are written in separate `*.css.ts` (or `*.css.js`) files and all code within them is executed during the build process rather than in your user's browser. If you want to keep your CSS bundle size to a minimum, Vanilla Extract also provides an official library called [Sprinkles][sprinkles] that lets you define a custom set of utility classes and a type-safe function for accessing them at runtime. + +First, ensure you've set up [CSS bundling][css-bundling] in your application. + +Next, install Vanilla Extract's core styling package as a dev dependency. + +```sh +npm install -D @vanilla-extract/css +``` + +Then, to enable Vanilla Extract, set the `future.unstable_vanillaExtract` feature flag in `remix.config.js`. + +```js filename=remix.config.js +/** @type {import('@remix-run/dev').AppConfig} */ +module.exports = { + future: { + unstable_vanillaExtract: true, + }, + // ... +}; +``` + +With this feature flag enabled, you can now opt into Vanilla Extract via the `.css.ts`/`.css.js` file name convention. For example: + +```ts filename=app/components/button/styles.css.ts +import { style } from "@vanilla-extract/css"; + +export const root = style({ + border: 'solid 1px', + background: 'white', + color: '#454545', +}); +``` + +```tsx filename=app/components/button/index.js lines=[1,9] +import * as styles from "./styles.css"; // Note that `.ts` is omitted here + +export const Button = React.forwardRef( + ({ children, ...props }, ref) => { + return ( +