Skip to content

Commit

Permalink
Convert "Canary" callouts to "React 19 beta"
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Apr 28, 2024
1 parent 01edd5c commit 71126fd
Show file tree
Hide file tree
Showing 37 changed files with 303 additions and 160 deletions.
32 changes: 32 additions & 0 deletions src/components/Icon/IconRocket.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/

import {memo} from 'react';

export const IconRocket = memo<
JSX.IntrinsicElements['svg'] & {title?: string; size?: 's' | 'md'}
>(function IconRocket({className, size = 'md'}) {
return (
<svg
className={className}
aria-hidden="true"
width={size === 's' ? '1.2em' : '1.5em'}
height={size === 's' ? '1.2em' : '1.5em'}
fill="currentColor"
version="1.1"
viewBox="0 0 1200 1200"
xmlns="http://www.w3.org/2000/svg">
<g fillRule="evenodd">
<path d="m911.8 288.2c65.051 65.051 65.051 170.6 0 235.65-65.051 65.051-170.6 65.051-235.65 0-65.051-65.051-65.051-170.6 0-235.65 65.051-65.051 170.6-65.051 235.65 0zm-53.051 53.051c-35.75-35.801-93.801-35.801-129.55 0-35.801 35.75-35.801 93.801 0 129.55 35.75 35.801 93.801 35.801 129.55 0 35.801-35.75 35.801-93.801 0-129.55z" />
<path d="m1122.2 103.4s96.648 328.1-194.4 619.1c-130.75 130.75-303.25 226.75-440.75 250.5-12.102 2.0508-24.449-1.8984-33.102-10.648l-231.55-234.8c-8.6484-8.8008-12.449-21.301-10.102-33.398 26.102-135.4 135.45-292.2 265.2-421.95 291-291.05 619.1-194.4 619.1-194.4 12.352 3.6016 22 13.25 25.602 25.602zm-67.5 41.898c-70.898-12.898-308.6-35.602-524.15 179.9-112.35 112.35-210.4 245.4-240.4 364.25 0 0 203.05 205.9 203.1 205.9 121.75-26.852 268.4-112.75 381.55-225.9 215.5-215.55 192.8-453.25 179.9-524.15z" />
<path d="m151.55 543.85 124 20.648c20.398 3.3984 34.25 22.75 30.801 43.148-3.3984 20.449-22.699 34.25-43.148 30.852l-144.35-24.051c-22.148-3.6992-40.699-18.949-48.602-40-7.9492-21.051-4.0508-44.699 10.199-62.148l122.85-150.15c15.051-18.398 36.898-30 60.551-32.148l179.55-16.301c20.602-1.8984 38.852 13.352 40.75 33.949 1.8516 20.602-13.352 38.852-33.949 40.75l-179.55 16.301c-3.6484 0.35156-7 2.1016-9.3008 4.9492z" />
<path d="m656.15 1048.4 134.2-109.8c2.8516-2.3008 4.6016-5.6484 4.9492-9.3008l16.301-179.55c1.8984-20.602 20.148-35.801 40.75-33.949 20.602 1.8984 35.852 20.148 33.949 40.75l-16.301 179.55c-2.1484 23.648-13.75 45.5-32.148 60.551l-150.15 122.85c-17.449 14.25-41.102 18.148-62.148 10.199-21.051-7.8984-36.301-26.449-40-48.602l-29.25-175.7c-3.3984-20.398 10.398-39.75 30.801-43.148 20.449-3.3984 39.75 10.449 43.148 30.852l25.898 155.3z" />
<path d="m310.9 560.4c-14.648-14.648-14.648-38.398 0-53.051 14.648-14.648 38.398-14.648 53.051 0l328.7 328.7c14.648 14.648 14.648 38.398 0 53.051-14.648 14.648-38.398 14.648-53.051 0z" />
<path d="m383.95 982.15c14.648-14.602 38.398-14.602 53.051 0 14.602 14.648 14.602 38.398 0 53.051l-91.352 91.301c-14.602 14.648-38.398 14.648-53 0-14.648-14.602-14.648-38.398 0-53z" />
<path d="m237.85 909.1c14.648-14.602 38.398-14.602 53.051 0 14.602 14.648 14.602 38.398 0 53.051l-127.85 127.85c-14.648 14.648-38.398 14.648-53.051 0-14.648-14.648-14.648-38.398 0-53.051z" />
<path d="m164.8 763c14.648-14.602 38.398-14.602 53.051 0 14.602 14.648 14.602 38.398 0 53.051l-91.352 91.301c-14.602 14.648-38.398 14.648-53 0-14.648-14.602-14.648-38.398 0-53z" />
</g>
</svg>
);
});
15 changes: 11 additions & 4 deletions src/components/Layout/Sidebar/SidebarLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface SidebarLinkProps {
selected?: boolean;
title: string;
level: number;
canary?: boolean;
version?: 'canary' | 'major';
icon?: React.ReactNode;
isExpanded?: boolean;
hideArrow?: boolean;
Expand All @@ -27,7 +27,7 @@ export function SidebarLink({
href,
selected = false,
title,
canary,
version,
level,
isExpanded,
hideArrow,
Expand Down Expand Up @@ -75,10 +75,17 @@ export function SidebarLink({
{/* This here needs to be refactored ofc */}
<div>
{title}{' '}
{canary && (
{version === 'major' && (
<span
title="- This feature is available in React 19 beta and the React canary channel"
className={`text-xs px-1 ms-1 rounded bg-gray-10 dark:bg-gray-40 dark:bg-opacity-20 text-gray-40 dark:text-gray-40`}>
React 19
</span>
)}
{version === 'canary' && (
<IconCanary
title=" - This feature is available in the latest Canary"
className="ms-2 text-gray-30 dark:text-gray-60 inline-block w-4 h-4 align-[-3px]"
className="ms-1 text-gray-30 dark:text-gray-60 inline-block w-3.5 h-3.5 align-[-3px]"
/>
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Layout/Sidebar/SidebarRouteTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function SidebarRouteTree({
path,
title,
routes,
canary,
version,
heading,
hasSectionHeader,
sectionHeader,
Expand Down Expand Up @@ -120,7 +120,7 @@ export function SidebarRouteTree({
selected={selected}
level={level}
title={title}
canary={canary}
version={version}
isExpanded={isExpanded}
hideArrow={isForceExpanded}
/>
Expand All @@ -144,7 +144,7 @@ export function SidebarRouteTree({
selected={selected}
level={level}
title={title}
canary={canary}
version={version}
/>
</li>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Layout/getRouteMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export type RouteTag =
export interface RouteItem {
/** Page title (for the sidebar) */
title: string;
/** Optional canary flag for heading */
canary?: boolean;
/** Optional version flag for heading */
version?: 'canary' | 'major';
/** Optional page description for heading */
description?: string;
/* Additional meta info for page tagging */
Expand Down
34 changes: 30 additions & 4 deletions src/components/MDX/ExpandableCallout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import {IconNote} from '../Icon/IconNote';
import {IconWarning} from '../Icon/IconWarning';
import {IconPitfall} from '../Icon/IconPitfall';
import {IconCanary} from '../Icon/IconCanary';
import {IconRocket} from '../Icon/IconRocket';

type CalloutVariants = 'deprecated' | 'pitfall' | 'note' | 'wip' | 'canary';
type CalloutVariants =
| 'deprecated'
| 'pitfall'
| 'note'
| 'wip'
| 'canary'
| 'major'
| 'rsc';

interface ExpandableCalloutProps {
children: React.ReactNode;
Expand Down Expand Up @@ -59,6 +67,22 @@ const variantMap = {
overlayGradient:
'linear-gradient(rgba(249, 247, 243, 0), rgba(249, 247, 243, 1)',
},
major: {
title: 'React 19',
Icon: IconRocket,
containerClasses: 'bg-blue-10 dark:bg-blue-60 dark:bg-opacity-20',
textColor: 'text-blue-50 dark:text-blue-40',
overlayGradient:
'linear-gradient(rgba(249, 247, 243, 0), rgba(249, 247, 243, 1)',
},
rsc: {
title: 'React Server Components',
Icon: null,
containerClasses: 'bg-blue-10 dark:bg-blue-60 dark:bg-opacity-20',
textColor: 'text-blue-50 dark:text-blue-40',
overlayGradient:
'linear-gradient(rgba(249, 247, 243, 0), rgba(249, 247, 243, 1)',
},
};

function ExpandableCallout({children, type = 'note'}: ExpandableCalloutProps) {
Expand All @@ -72,9 +96,11 @@ function ExpandableCallout({children, type = 'note'}: ExpandableCalloutProps) {
variant.containerClasses
)}>
<h3 className={cn('text-2xl font-display font-bold', variant.textColor)}>
<variant.Icon
className={cn('inline me-3 mb-1 text-lg', variant.textColor)}
/>
{variant.Icon && (
<variant.Icon
className={cn('inline me-2 mb-1 text-lg', variant.textColor)}
/>
)}
{variant.title}
</h3>
<div className="relative">
Expand Down
32 changes: 32 additions & 0 deletions src/components/MDX/MDXComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ const Canary = ({children}: {children: React.ReactNode}) => (
<ExpandableCallout type="canary">{children}</ExpandableCallout>
);

const NextMajor = ({children}: {children: React.ReactNode}) => (
<ExpandableCallout type="major">{children}</ExpandableCallout>
);

const RSC = ({children}: {children: React.ReactNode}) => (
<ExpandableCallout type="rsc">{children}</ExpandableCallout>
);

const CanaryBadge = ({title}: {title: string}) => (
<span
title={title}
Expand All @@ -109,6 +117,26 @@ const CanaryBadge = ({title}: {title: string}) => (
</span>
);

const NextMajorBadge = ({title}: {title: string}) => (
<span
title={title}
className={
'text-base font-display px-2 py-0.5 font-bold bg-blue-10 dark:bg-blue-60 text-gray-60 dark:text-gray-10 rounded'
}>
React 19
</span>
);

const RSCBadge = ({title}: {title: string}) => (
<span
title={title}
className={
'text-base font-display px-2 py-0.5 font-bold bg-blue-10 dark:bg-blue-50 text-gray-60 dark:text-gray-10 rounded'
}>
RSC
</span>
);

const Blockquote = ({
children,
...props
Expand Down Expand Up @@ -448,6 +476,10 @@ export const MDXComponents = {
Note,
Canary,
CanaryBadge,
NextMajor,
NextMajorBadge,
RSC,
RSCBadge,
PackageImport,
ReadBlogPost,
Recap,
Expand Down
6 changes: 3 additions & 3 deletions src/content/learn/manipulating-the-dom-with-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ In this example, `itemsRef` doesn't hold a single DOM node. Instead, it holds a

This lets you read individual DOM nodes from the Map later.

<Canary>
<NextMajor>

This example shows another approach for managing the Map with a `ref` callback cleanup function.
Starting in React 19 callback refs can return a cleanup function. When the cleanup function is provided, React will not call the `ref` callback with `null` and call the cleanup function instead:

```js
<li
Expand All @@ -361,7 +361,7 @@ This example shows another approach for managing the Map with a `ref` callback c
>
```

</Canary>
</NextMajor>

</DeepDive>

Expand Down
12 changes: 7 additions & 5 deletions src/content/reference/react-dom/client/createRoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ An app fully built with React will usually only have one `createRoot` call for i
* **optional** `options`: An object with options for this React root.
* <CanaryBadge title="This feature is only available in the Canary channel" /> **optional** `onCaughtError`: Callback called when React catches an error in an Error Boundary. Called with the `error` caught by the Error Boundary, and an `errorInfo` object containing the `componentStack`.
* <CanaryBadge title="This feature is only available in the Canary channel" /> **optional** `onUncaughtError`: Callback called when an error is thrown and not caught by an Error Boundary. Called with the `error` that was thrown, and an `errorInfo` object containing the `componentStack`.
* <NextMajorBadge title="This feature is available in React 19 beta and the React canary channel" /> **optional** `onCaughtError`: Callback called when React catches an error in an Error Boundary. Called with the `error` caught by the Error Boundary, and an `errorInfo` object containing the `componentStack`.
* <NextMajorBadge title="This feature is available in React 19 beta and the React canary channel" /> **optional** `onUncaughtError`: Callback called when an error is thrown and not caught by an Error Boundary. Called with the `error` that was thrown, and an `errorInfo` object containing the `componentStack`.
* **optional** `onRecoverableError`: Callback called when React automatically recovers from errors. Called with an `error` React throws, and an `errorInfo` object containing the `componentStack`. Some recoverable errors may include the original error cause as `error.cause`.
* **optional** `identifierPrefix`: A string prefix React uses for IDs generated by [`useId`.](/reference/react/useId) Useful to avoid conflicts when using multiple roots on the same page.
Expand Down Expand Up @@ -346,11 +346,13 @@ It is uncommon to call `render` multiple times. Usually, your components will [u
### Show a dialog for uncaught errors {/*show-a-dialog-for-uncaught-errors*/}
<Canary>
<NextMajor>
`onUncaughtError` is only available in the latest React Canary release.
`onUncaughtError` is available in React 19 beta, and the React canary channel.
</Canary>
Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
</NextMajor>
By default, React will log all uncaught errors to the console. To implement your own error reporting, you can provide the optional `onUncaughtError` root option:
Expand Down
12 changes: 7 additions & 5 deletions src/content/reference/react-dom/client/hydrateRoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ React will attach to the HTML that exists inside the `domNode`, and take over ma
* **optional** `options`: An object with options for this React root.
* <CanaryBadge title="This feature is only available in the Canary channel" /> **optional** `onCaughtError`: Callback called when React catches an error in an Error Boundary. Called with the `error` caught by the Error Boundary, and an `errorInfo` object containing the `componentStack`.
* <CanaryBadge title="This feature is only available in the Canary channel" /> **optional** `onUncaughtError`: Callback called when an error is thrown and not caught by an Error Boundary. Called with the `error` that was thrown and an `errorInfo` object containing the `componentStack`.
* <NextMajorBadge title="This feature is available in React 19 beta and the React canary channel" /> **optional** `onCaughtError`: Callback called when React catches an error in an Error Boundary. Called with the `error` caught by the Error Boundary, and an `errorInfo` object containing the `componentStack`.
* <NextMajorBadge title="This feature is available in React 19 beta and the React canary channel" /> **optional** `onUncaughtError`: Callback called when an error is thrown and not caught by an Error Boundary. Called with the `error` that was thrown and an `errorInfo` object containing the `componentStack`.
* **optional** `onRecoverableError`: Callback called when React automatically recovers from errors. Called with the `error` React throws, and an `errorInfo` object containing the `componentStack`. Some recoverable errors may include the original error cause as `error.cause`.
* **optional** `identifierPrefix`: A string prefix React uses for IDs generated by [`useId`.](/reference/react/useId) Useful to avoid conflicts when using multiple roots on the same page. Must be the same prefix as used on the server.
Expand Down Expand Up @@ -376,11 +376,13 @@ It is uncommon to call [`root.render`](#root-render) on a hydrated root. Usually
### Show a dialog for uncaught errors {/*show-a-dialog-for-uncaught-errors*/}
<Canary>
<NextMajor>
`onUncaughtError` is only available in the latest React Canary release.
`onUncaughtError` is currently available in React 19 beta, and the React canary channel.
</Canary>
Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
</NextMajor>
By default, React will log all uncaught errors to the console. To implement your own error reporting, you can provide the optional `onUncaughtError` root option:
Expand Down
5 changes: 3 additions & 2 deletions src/content/reference/react-dom/components/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ React will also call your `ref` callback whenever you pass a *different* `ref` c

* `node`: A DOM node or `null`. React will pass you the DOM node when the ref gets attached, and `null` when the `ref` gets detached. Unless you pass the same function reference for the `ref` callback on every render, the callback will get temporarily detached and re-attached during every re-render of the component.

<Canary>
<NextMajor>

#### Returns {/*returns*/}
In React 19 beta, ref callbacks can return a cleanup function. When a cleanup function is provided, React will not call the `ref` callback with `null` and will call the cleanup function instead.

* **optional** `cleanup function`: When the `ref` is detached, React will call the cleanup function. If a function is not returned by the `ref` callback, React will call the callback again with `null` as the argument when the `ref` gets detached.

Expand All @@ -282,7 +283,7 @@ React will also call your `ref` callback whenever you pass a *different* `ref` c
* When Strict Mode is on, React will **run one extra development-only setup+cleanup cycle** before the first real setup. This is a stress-test that ensures that your cleanup logic "mirrors" your setup logic and that it stops or undoes whatever the setup is doing. If this causes a problem, implement the cleanup function.
* When you pass a *different* `ref` callback, React will call the *previous* callback's cleanup function if provided. If not cleanup function is defined, the `ref` callback will be called with `null` as the argument. The *next* function will be called with the DOM node.

</Canary>
</NextMajor>

---

Expand Down
11 changes: 7 additions & 4 deletions src/content/reference/react-dom/components/form.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
title: "<form>"
canary: true
---

<Canary>
<NextMajor>

React's extensions to `<form>` are currently only available in React's canary and experimental channels. In stable releases of React, `<form>` works only as a [built-in browser HTML component](https://react.dev/reference/react-dom/components#all-html-components). Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
React's extensions to `<form>` are currently available in React 19 beta and React's canary and experimental channels.

</Canary>
In stable releases of React, `<form>` works only as a [built-in browser HTML component](https://react.dev/reference/react-dom/components#all-html-components).

Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).

</NextMajor>


<Intro>
Expand Down
18 changes: 11 additions & 7 deletions src/content/reference/react-dom/components/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
title: "<input>"
---

<NextMajor>

React's extensions to the `formAction` prop of `<input>` is currently available in React 19 beta and the React canary channel.

In stable releases of React, `<input>` works only as a [built-in browser HTML component](https://react.dev/reference/react-dom/components#all-html-components).

Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).

</NextMajor>

<Intro>

The [built-in browser `<input>` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) lets you render different kinds of form inputs.
Expand Down Expand Up @@ -32,13 +42,7 @@ To display an input, render the [built-in browser `<input>`](https://developer.m

`<input>` supports all [common element props.](/reference/react-dom/components/common#props)

<Canary>

React's extensions to the `formAction` prop are currently only available in React's Canary and experimental channels. In stable releases of React, `formAction` works only as a [built-in browser HTML component](/reference/react-dom/components#all-html-components). Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).

</Canary>

[`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): A string or function. Overrides the parent `<form action>` for `type="submit"` and `type="image"`. When a URL is passed to `action` the form will behave like a standard HTML form. When a function is passed to `formAction` the function will handle the form submission. See [`<form action>`](/reference/react-dom/components/form#props).
- <NextMajorBadge title="This feature is only available in React 19 beta and the React Canary channel"/> [`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): A string or function. Overrides the parent `<form action>` for `type="submit"` and `type="image"`. When a URL is passed to `action` the form will behave like a standard HTML form. When a function is passed to `formAction` the function will handle the form submission. See [`<form action>`](/reference/react-dom/components/form#props).

You can [make an input controlled](#controlling-an-input-with-a-state-variable) by passing one of these props:

Expand Down
11 changes: 7 additions & 4 deletions src/content/reference/react-dom/components/link.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
link: "<link>"
canary: true
---

<Canary>
<NextMajor>

React's extensions to `<link>` are currently only available in React's canary and experimental channels. In stable releases of React `<link>` works only as a [built-in browser HTML component](https://react.dev/reference/react-dom/components#all-html-components). Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).
React's extensions to `<link>` are currently available in React 19 beta and the React canary channel.

</Canary>
In stable releases of React `<link>` works only as a [built-in browser HTML component](https://react.dev/reference/react-dom/components#all-html-components).

Learn more about [React's release channels here](/community/versioning-policy#all-release-channels).

</NextMajor>

<Intro>

Expand Down

0 comments on commit 71126fd

Please sign in to comment.