Skip to content

Commit 56c4d52

Browse files
committed
Fix broken examples and code highlighting in ViewTransition and addTransitionType
The fixed example in "two <ViewTransition name=%s> components" still passes item={item} while Item reads {id}, so every item is named "item-undefined" and triggers the same error. The first addTransitionType example has a syntax error ({action)) and a fence without a language, so its CodeSteps never render. Line highlights written as [3, 5] / [3] / [11] are ignored by getHighlightLines, which only reads {...}; switch them to braces and update ranges that no longer match the code. Also use checked instead of value on the "Fast" checkbox, move key to the outer element in the wrapper snippet, drop the nonexistent `layout` prop from addTransitionType, and remove a "sidebar" reference from the Activity example, which only has a counter.
1 parent 2e6dca1 commit 56c4d52

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎src/content/reference/react/ViewTransition.md‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ button:hover {
442442

443443
If there's a `<div>` above `<ViewTransition>`, no exit/enter animations trigger:
444444

445-
```js [3, 5]
445+
```js {3,7}
446446
function Item() {
447447
return (
448448
<div> {/* 🚩<div> above <ViewTransition> breaks exit/enter */}
@@ -473,7 +473,7 @@ If you want to animate a component in and out while preserving its state, or pre
473473

474474
```
475475

476-
In this example, `Counter` has a counter with internal state. Try incrementing the counter, hiding it, then showing it again. The counter's value is preserved while the sidebar animates in and out:
476+
In this example, `Counter` has a counter with internal state. Try incrementing the counter, hiding it, then showing it again. The counter's value is preserved while `Counter` animates in and out:
477477

478478
<Sandpack>
479479

@@ -574,7 +574,7 @@ function Counter() {
574574

575575
</Sandpack>
576576

577-
Without `<Activity>`, the counter would reset to `0` every time the sidebar reappears.
577+
Without `<Activity>`, the counter would reset to `0` every time it reappears.
578578

579579
---
580580

@@ -1235,8 +1235,8 @@ button:hover {
12351235

12361236
This means you might want to avoid wrapper elements in lists where you want to allow the Component to control its own reorder animation:
12371237

1238-
```
1239-
items.map(item => <div><Component key={item.id} item={item} /></div>)
1238+
```js
1239+
items.map(item => <div key={item.id}><Component item={item} /></div>)
12401240
```
12411241

12421242
The above rule also applies if one of the items updates to resize, which then causes the siblings to resize, it'll also animate its sibling `<ViewTransition>` but only if they're immediate siblings.
@@ -2630,7 +2630,7 @@ export default function Component() {
26302630
return (
26312631
<>
26322632
<div>
2633-
Fast: <input type="checkbox" onChange={() => {setIsFast(f => !f)}} value={isFast}></input>
2633+
Fast: <input type="checkbox" onChange={() => {setIsFast(f => !f)}} checked={isFast}></input>
26342634
</div><br />
26352635
<button
26362636
onClick={() => {
@@ -2783,7 +2783,7 @@ If a `startTransition` is started from the legacy popstate event, such as during
27832783

27842784
`<ViewTransition>` only activates if it is placed before any DOM node:
27852785

2786-
```js [3, 5]
2786+
```js {3,5}
27872787
function Component() {
27882788
return (
27892789
<div>
@@ -2795,7 +2795,7 @@ function Component() {
27952795

27962796
To fix, ensure that the `<ViewTransition>` comes before any other DOM nodes:
27972797

2798-
```js [3, 5]
2798+
```js {3,5}
27992799
function Component() {
28002800
return (
28012801
<ViewTransition>
@@ -2809,7 +2809,7 @@ function Component() {
28092809

28102810
This error occurs when two `<ViewTransition>` components with the same `name` are mounted at the same time:
28112811

2812-
```js [3]
2812+
```js {3}
28132813
function Item() {
28142814
// 🚩 All items will get the same "name".
28152815
return <ViewTransition name="item">...</ViewTransition>;
@@ -2848,7 +2848,7 @@ The existing `<ViewTransition name=%s>` duplicate has this stack trace.
28482848

28492849
To fix, ensure that there's only one `<ViewTransition>` with the same name mounted at a time in the entire app by ensuring the `name` is unique, or adding an `id` to the name:
28502850

2851-
```js [3]
2851+
```js {3}
28522852
function Item({id}) {
28532853
// ✅ All items will get a unique name.
28542854
return <ViewTransition name={`item-${id}`}>...</ViewTransition>;
@@ -2858,7 +2858,7 @@ function ItemList({items}) {
28582858
return (
28592859
<>
28602860
{items.map((item) => (
2861-
<Item key={item.id} item={item} />
2861+
<Item key={item.id} id={item.id} />
28622862
))}
28632863
</>
28642864
);

‎src/content/reference/react/addTransitionType.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ startTransition(() => {
4545

4646
Call `addTransitionType` inside of `startTransition` to indicate the cause of a transition:
4747

48-
``` [[1, 6, "addTransitionType"], [2, 5, "startTransition", [3, 6, "'submit-click'"]]
48+
```js [[1, 6, "addTransitionType"], [2, 5, "startTransition"], [3, 6, "'submit-click'"]]
4949
import { startTransition, addTransitionType } from 'react';
5050

51-
function Submit({action) {
51+
function Submit({action}) {
5252
function handleClick() {
5353
startTransition(() => {
5454
addTransitionType('submit-click');
@@ -78,7 +78,7 @@ When a [`ViewTransition`](/reference/react/ViewTransition) activates from a tran
7878

7979
This allows you to customize different animations based on CSS scopes:
8080

81-
```js [11]
81+
```js {10}
8282
function Component() {
8383
return (
8484
<ViewTransition>
@@ -127,7 +127,7 @@ startTransition(() => {
127127

128128
If multiple types match, then they're joined together. If no types match then the special "default" entry is used instead. If any type has the value "none" then that wins and the ViewTransition is disabled (not assigned a name).
129129

130-
These can be combined with enter/exit/update/layout/share props to match based on kind of trigger and Transition Type.
130+
These can be combined with enter/exit/update/share props to match based on kind of trigger and Transition Type.
131131

132132
```js
133133
<ViewTransition enter={{

0 commit comments

Comments
 (0)