Skip to content

Commit

Permalink
Merge branch 'release-next'
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed Jan 18, 2023
2 parents 00fa589 + 13d436d commit 006b58b
Show file tree
Hide file tree
Showing 118 changed files with 7,420 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
plugins: ["markdown"],
overrides: [
{
files: ["rollup.config.js"],
files: ["rollup.config.js", "**/*.md"],
rules: {
"import/no-extraneous-dependencies": OFF,
},
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.changeset/*.md
.changeset/*.md
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
- sndrem
- sobrinho
- squidpunch
- staylor
- stephanerangaya
- SufianBabri
- supachaidev
Expand Down
3 changes: 2 additions & 1 deletion docs/file-conventions/remix-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ The `serverBuildTarget` can be one of the following:

## serverDependenciesToBundle

A list of regex patterns that determines if a module is transpiled and included in the server bundle. This can be useful when consuming ESM only packages in a CJS build.
A list of regex patterns that determines if a module is transpiled and included in the server bundle. This can be useful when consuming ESM only packages in a CJS build, or when consuming packages with [CSS side-effect imports][css-side-effect-imports].

For example, the `unified` ecosystem is all ESM-only. Let's also say we're using a `@sindresorhus/slugify` which is ESM-only as well. Here's how you would be able to consume those packages in a CJS app without having to use dynamic imports:

Expand Down Expand Up @@ -186,3 +186,4 @@ There are a few conventions that Remix uses you should be aware of.
[an-awesome-visualization]: https://remix-routing-demo.netlify.app
[remix-dev]: ../other-api/dev#remix-dev
[app-directory]: #appDirectory
[css-side-effect-imports]: ../guides/styling#css-side-effect-imports
9 changes: 4 additions & 5 deletions docs/guides/mdx.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can reference your frontmatter data through "attributes". The title of this

### Advanced Example

You can even export all the other things in this module that you can in regular route modules in your mdx files like `loader` and `action`:
You can even export all the other things in this module that you can in regular route modules in your mdx files like `loader`, `action`, and `handle`:

```mdx
---
Expand All @@ -77,6 +77,9 @@ meta:

headers:
Cache-Control: no-cache

handle:
someData: abc
---

import styles from "./first-post.css";
Expand All @@ -85,10 +88,6 @@ export const links = () => [
{ rel: "stylesheet", href: styles },
];

export const handle = {
someData: "abc",
};

import { json } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";

Expand Down
5 changes: 3 additions & 2 deletions docs/guides/migrating-react-router-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ The answer to all of these questions is up to your bundler, _not you_. We think

**Note:** Remix does not currently support CSS processing directly. If you use preprocessors like Sass, Less, or PostCSS, you can run those as a separate process in development.

We also do not yet support CSS Modules, as that requires compiler integration and current approaches are not aligned with our design philosophy. We are actively working on a solution and plan to have an API for CSS Modules very soon.
We do process [CSS Modules][css-modules], but support is currently [opt-in behind a feature flag][css-modules].

</docs-info>

Expand Down Expand Up @@ -642,4 +642,5 @@ Now then, go off and _remix your app_. We think you'll like what you build along
[routing-in-remix]: ./routing
[styling-in-remix]: ./styling
[frequently-asked-questions]: ../pages/faq
[common-gotchas]: ../pages/gotchas
[common-gotchas]: ../pages/currently
[css-modules]: ./styling#css-modules
175 changes: 175 additions & 0 deletions docs/guides/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,175 @@ Other CSS-in-JS libraries will have a similar setup. If you've got a CSS framewo

NOTE: You may run into hydration warnings when using Styled Components. Hopefully [this issue][styled-components-issue] will be fixed soon.

## CSS Bundling

<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>

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.

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.

To get access to the CSS bundle, first install the `@remix-run/css-bundle` package.

```sh
npm install @remix-run/css-bundle
```

Then, import `cssBundleHref` and add it to a link descriptor—most likely in `root.tsx` so that it applies to your entire application.

```tsx filename=root.tsx lines=[2,6-8]
import type { LinksFunction } from "@remix-run/node"; // or cloudflare/deno
import { cssBundleHref } from "@remix-run/css-bundle";

export const links: LinksFunction = () => {
return [
...(cssBundleHref
? [{ rel: "stylesheet", href: cssBundleHref }]
: []),
// ...
];
};
```

With this link tag inserted into the page, you're now ready to start using the various CSS bundling features built into Remix.

### CSS Modules

<docs-warning>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.</docs-warning>

First, ensure you've set up [CSS bundling][css-bundling] in your application.

Then, to enable [CSS Modules], set the `future.unstable_cssModules` feature flag in `remix.config.js`.

```js filename=remix.config.js
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
future: {
unstable_cssModules: true,
},
// ...
};
```

With this feature flag enabled, you can now opt into CSS Modules via the `.module.css` file name convention. For example:

```css filename=app/components/button/styles.module.css
.root {
border: solid 1px;
background: white;
color: #454545;
}
```

```tsx filename=app/components/button/index.js lines=[1,9]
import styles from "./styles.module.css";

export const Button = React.forwardRef(
({ children, ...props }, ref) => {
return (
<button
{...props}
ref={ref}
className={styles.root}
/>
);
}
);
Button.displayName = "Button";
```

### Vanilla Extract

<docs-warning>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.</docs-warning>

[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 (
<button
{...props}
ref={ref}
className={styles.root}
/>
);
}
);
Button.displayName = "Button";
```

### CSS Side-Effect Imports

<docs-warning>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.</docs-warning>

Some NPM packages use side-effect imports of plain CSS files (e.g. `import "./styles.css"`) to declare the CSS dependencies of JavaScript files. If you want to consume one of these packages, first ensure you've set up [CSS bundling][css-bundling] in your application.

Then, set the `future.unstable_cssSideEffectImports` feature flag in `remix.config.js`.

```js filename=remix.config.js
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
future: {
unstable_cssSideEffectImports: true,
},
// ...
};
```

Finally, since JavaScript runtimes don't support importing CSS in this way, you'll also need to add any relevant packages to the [`serverDependenciesToBundle`][server-dependencies-to-bundle] option in your `remix.config.js` file. This ensures that any CSS imports are compiled out of your code before running it on the server. For example, to use React Spectrum:

```js filename=remix.config.js
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverDependenciesToBundle: [
/^@adobe\/react-spectrum/,
/^@react-spectrum/,
/^@spectrum-icons/,
],
future: {
unstable_cssSideEffectImports: true,
},
// ...
};
```

[custom-properties]: https://developer.mozilla.org/en-US/docs/Web/CSS/--*
[link]: ../components/link
[route-module-links]: ../route/links
Expand All @@ -774,3 +943,9 @@ NOTE: You may run into hydration warnings when using Styled Components. Hopefull
[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
[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

0 comments on commit 006b58b

Please sign in to comment.