Unverified Commit 2514e133 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Add experimental flag for View Transitions (#74659)

Will be stacked on next React sync which includes
`unstable_ViewTransition`.

Allows using React's `unstable_ViewTransition` Component behind the
`experimental.viewTransition` flag.

Right now it just opts into React's experimental build but may later
house Next.js specific features like Transition Types for navigations.
parent 5929cf77
......@@ -723,6 +723,7 @@ pub struct ExperimentalConfig {
/// @see [api reference](https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes)
typed_routes: Option<bool>,
url_imports: Option<serde_json::Value>,
view_transition: Option<bool>,
/// This option is to enable running the Webpack build in a worker thread
/// (doesn't apply to Turbopack).
webpack_build_worker: Option<bool>,
......@@ -1396,6 +1397,11 @@ impl NextConfig {
Vc::cell(self.experimental.react_owner_stack.unwrap_or(false))
}
#[turbo_tasks::function]
pub fn enable_view_transition(&self) -> Vc<bool> {
Vc::cell(self.experimental.view_transition.unwrap_or(false))
}
#[turbo_tasks::function]
pub fn enable_dynamic_io(&self) -> Vc<bool> {
Vc::cell(self.experimental.dynamic_io.unwrap_or(false))
......
......@@ -120,6 +120,7 @@ pub async fn get_next_client_import_map(
let react_flavor = if *next_config.enable_ppr().await?
|| *next_config.enable_taint().await?
|| *next_config.enable_react_owner_stack().await?
|| *next_config.enable_view_transition().await?
{
"-experimental"
} else {
......@@ -719,7 +720,8 @@ async fn rsc_aliases(
let ppr = *next_config.enable_ppr().await?;
let taint = *next_config.enable_taint().await?;
let react_owner_stack = *next_config.enable_react_owner_stack().await?;
let react_channel = if ppr || taint || react_owner_stack {
let view_transition = *next_config.enable_view_transition().await?;
let react_channel = if ppr || taint || react_owner_stack || view_transition {
"-experimental"
} else {
""
......
import type { NextConfig } from '../server/config-shared'
export function needsExperimentalReact(config: NextConfig) {
const { ppr, taint, reactOwnerStack } = config.experimental || {}
return Boolean(ppr || taint || reactOwnerStack)
const { ppr, taint, reactOwnerStack, viewTransition } =
config.experimental || {}
return Boolean(ppr || taint || reactOwnerStack || viewTransition)
}
......@@ -350,6 +350,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
swcTraceProfiling: z.boolean().optional(),
// NonNullable<webpack.Configuration['experiments']>['buildHttp']
urlImports: z.any().optional(),
viewTransition: z.boolean().optional(),
workerThreads: z.boolean().optional(),
webVitalsAttribution: z
.array(
......
......@@ -495,6 +495,11 @@ export interface ExperimentalConfig {
*/
useEarlyImport?: boolean
/**
* Enables view transitions by using the {@link https://github.com/facebook/react/pull/31975 unstable_ViewTransition} Component.
*/
viewTransition?: boolean
/**
* Enables `fetch` requests to be proxied to the experimental test proxy server
*/
......@@ -1183,6 +1188,7 @@ export const defaultConfig: NextConfig = {
webpackMemoryOptimizations: false,
optimizeServerReact: true,
useEarlyImport: false,
viewTransition: false,
staleTimes: {
dynamic: 0,
static: 300,
......
'use client'
import * as React from 'react'
export function Toggle() {
const [show, setShow] = React.useState(false)
React.useEffect(() => {
React.startTransition(() => {
setShow(true)
})
}, [])
return (
<div>
<button
onClick={() => {
React.startTransition(() => {
setShow((show) => !show)
})
}}
>
{show ? 'A' : 'B'}
</button>
{show ? <div>hello</div> : <section>Loading</section>}
</div>
)
}
import { unstable_ViewTransition as ViewTransition } from 'react'
import { Toggle } from './Toggle'
export default function BasicPage() {
return (
<ViewTransition name="page">
<Toggle />
</ViewTransition>
)
}
export default function Root({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
module.exports = {
experimental: {
viewTransition: true,
},
}
import * as path from 'path'
import { nextTestSetup } from 'e2e-utils'
import { BrowserInterface } from 'next-webdriver'
async function assertNoConsoleErrors(browser: BrowserInterface) {
const logs = await browser.log()
const warningsAndErrors = logs.filter((log) => {
return log.source === 'warning' || log.source === 'error'
})
expect(warningsAndErrors).toEqual([])
}
describe('view-transitions', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixtures/default'),
})
it('smoketest', async () => {
const browser = await next.browser('/basic')
await assertNoConsoleErrors(browser)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment