Skip to content

Commit 0d6c1c4

Browse files
committed
Use ViewTransition from Canary release channel
1 parent 993b25b commit 0d6c1c4

File tree

9 files changed

+386
-398
lines changed

9 files changed

+386
-398
lines changed

crates/next-core/src/next_config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,6 @@ pub struct ExperimentalConfig {
864864
trust_host_header: Option<bool>,
865865

866866
url_imports: Option<serde_json::Value>,
867-
view_transition: Option<bool>,
868867
/// This option is to enable running the Webpack build in a worker thread
869868
/// (doesn't apply to Turbopack).
870869
webpack_build_worker: Option<bool>,
@@ -1722,11 +1721,6 @@ impl NextConfig {
17221721
Vc::cell(self.experimental.taint.unwrap_or(false))
17231722
}
17241723

1725-
#[turbo_tasks::function]
1726-
pub fn enable_view_transition(&self) -> Vc<bool> {
1727-
Vc::cell(self.experimental.view_transition.unwrap_or(false))
1728-
}
1729-
17301724
#[turbo_tasks::function]
17311725
pub fn enable_cache_components(&self) -> Vc<bool> {
17321726
Vc::cell(self.experimental.cache_components.unwrap_or(false))

crates/next-core/src/next_import_map.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,13 @@ pub async fn get_next_client_import_map(
127127
match &ty {
128128
ClientContextType::Pages { .. } => {}
129129
ClientContextType::App { app_dir } => {
130-
let react_flavor = if *next_config.enable_ppr().await?
131-
|| *next_config.enable_taint().await?
132-
|| *next_config.enable_view_transition().await?
133-
{
134-
"-experimental"
135-
} else {
136-
""
137-
};
130+
// Keep in sync with file:///./../../../packages/next/src/lib/needs-experimental-react.ts
131+
let react_flavor =
132+
if *next_config.enable_ppr().await? || *next_config.enable_taint().await? {
133+
"-experimental"
134+
} else {
135+
""
136+
};
138137

139138
import_map.insert_exact_alias(
140139
rcstr!("react"),
@@ -833,12 +832,7 @@ async fn apply_vendored_react_aliases_server(
833832
) -> Result<()> {
834833
let ppr = *next_config.enable_ppr().await?;
835834
let taint = *next_config.enable_taint().await?;
836-
let view_transition = *next_config.enable_view_transition().await?;
837-
let react_channel = if ppr || taint || view_transition {
838-
"-experimental"
839-
} else {
840-
""
841-
};
835+
let react_channel = if ppr || taint { "-experimental" } else { "" };
842836
let react_condition = if ty.should_use_react_server_condition() {
843837
"server"
844838
} else {

docs/01-app/03-api-reference/05-config/01-next-config-js/viewTransition.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Enable ViewTransition API from React in App Router
44
version: experimental
55
---
66

7-
`viewTransition` is an experimental flag that enables the new experimental [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) in React. This API allows you to leverage the native View Transitions browser API to create seamless transitions between UI states.
7+
`viewTransition` is an experimental flag that enables the new [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) in React. This API allows you to leverage the native View Transitions browser API to create seamless transitions between UI states.
88

99
To enable this feature, you need to set the `viewTransition` property to `true` in your `next.config.js` file.
1010

@@ -19,19 +19,18 @@ const nextConfig = {
1919
module.exports = nextConfig
2020
```
2121

22-
> Important Notice: This feature is not developed or maintained by the Next.js team — it is an experimental API from the React team. It is still in **early stages** and **not recommended for production use**. The implementation is still being iterated on, and its behavior may change in future React releases.
23-
> Enabling this feature requires understanding the experimental nature of the API. To fully grasp its behavior, refer to the [React pull request](https://github.com/facebook/react/pull/31975) and related discussions.
22+
> Important Notice: The `<ViewTransition>` Component is already available in React's Canary release channel.
23+
> `experimental.viewTransition` is only required to enable deeper integration with Next.js features e.g. automatically
24+
> [adding Transition types](https://react.dev/reference/react/addTransitionType) for navigations. Next.js specific transition types are not implemented yet.
2425
2526
## Usage
2627

27-
Once enabled, you can import the `ViewTransition` component from React in your application:
28+
You can import the [`<ViewTransition>` Component](https://react.dev/reference/react/ViewTransition) from React in your application:
2829

2930
```jsx
30-
import { unstable_ViewTransition as ViewTransition } from 'react'
31+
import { ViewTransition } from 'react'
3132
```
3233

33-
However, documentation and examples are currently limited, and you will need to refer directly to React’s source code and discussions to understand how this works.
34-
3534
### Live Demo
3635

3736
Check out our [Next.js View Transition Demo](https://view-transition-example.vercel.app) to see this feature in action.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@
163163
"@types/jest": "29.5.5",
164164
"@types/node": "20.17.6",
165165
"@types/node-fetch": "2.6.1",
166-
"@types/react": "19.1.16",
167-
"@types/react-dom": "19.1.10",
166+
"@types/react": "19.2.2",
167+
"@types/react-dom": "19.2.1",
168168
"@types/relay-runtime": "14.1.13",
169169
"@types/string-hash": "1.1.1",
170170
"@types/trusted-types": "2.0.3",
@@ -319,8 +319,8 @@
319319
"@babel/parser": "7.27.0",
320320
"@babel/types": "7.27.0",
321321
"@babel/traverse": "7.27.0",
322-
"@types/react": "19.1.16",
323-
"@types/react-dom": "19.1.10",
322+
"@types/react": "19.2.2",
323+
"@types/react-dom": "19.2.1",
324324
"@types/retry": "0.12.0",
325325
"jest-snapshot": "30.0.0-alpha.6",
326326
"react": "19.3.0-canary-a4eb2dfa-20251006",
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { NextConfig } from '../server/config-shared'
22

3+
// Keep in sync with Turbopack's experimental React switch: file://./../../../../crates/next-core/src/next_import_map.rs
34
export function needsExperimentalReact(config: NextConfig) {
4-
const { ppr, taint, viewTransition } = config.experimental || {}
5-
return Boolean(ppr || taint || viewTransition)
5+
const { ppr, taint } = config.experimental || {}
6+
return Boolean(ppr || taint)
67
}

packages/next/src/server/config-shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ export interface ExperimentalConfig {
653653
useLightningcss?: boolean
654654

655655
/**
656-
* Enables view transitions by using the {@link https://github.com/facebook/react/pull/31975 unstable_ViewTransition} Component.
656+
* Enables view transitions by using the {@link https://react.dev/reference/react/ViewTransition ViewTransition} Component.
657657
*/
658658
viewTransition?: boolean
659659

0 commit comments

Comments
 (0)