@samitouri / QOS-React / commits / 3580584ba2

[playground] ViewTransition on tab switch (#34596)

<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. Before submitting a pull request, please make sure the following is done: 1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development. 5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`. 6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect". 7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`). 8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files. 9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`). 10. If you haven't already, complete the CLA. Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html --> ## Summary <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> Utilized `<ViewTransition>` to introduce a sliding animation upon switching between the Output and SourceMap tabs in the default playground view. ## How did you test this change? <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. How exactly did you verify that your PR solves the issue you wanted to solve? If you leave this empty, your PR will very likely be closed. --> https://github.com/user-attachments/assets/1ac93482-8104-4f9a-887e-6adca3537dca

Eugene Choi committed Sep 29, 2025 at 14:40 UTC 3580584ba2bdce17572aa356da1d6a09a2d2e3b3
4 files changed +52 -7
compiler/apps/playground/components/Editor/EditorImpl.tsx
+5 -1
@@ -24,7 +24,11 @@ import BabelPluginReactCompiler, {
24 printFunctionWithOutlined,
25 type LoggerEvent,
26 } from 'babel-plugin-react-compiler';
27 -import {useDeferredValue, useMemo} from 'react';
27 +import {
28 + useDeferredValue,
29 + useMemo,
30 + unstable_ViewTransition as ViewTransition,
31 +} from 'react';
32 import {useStore} from '../StoreContext';
33 import ConfigEditor from './ConfigEditor';
34 import Input from './Input';
compiler/apps/playground/components/TabbedWindow.tsx
+38 -6
@@ -4,8 +4,14 @@
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7 -import React from 'react';
7 +import React, {
8 + startTransition,
9 + useId,
10 + unstable_ViewTransition as ViewTransition,
11 + unstable_addTransitionType as addTransitionType,
12 +} from 'react';
13 import clsx from 'clsx';
14 +import {TOGGLE_TAB_TRANSITION} from '../lib/transitionTypes';
15
16 export default function TabbedWindow({
17 tabs,
@@ -16,6 +22,16 @@ export default function TabbedWindow({
22 activeTab: string;
23 onTabChange: (tab: string) => void;
24 }): React.ReactElement {
25 + const id = useId();
26 + const transitionName = `tab-highlight-${id}`;
27 +
28 + const handleTabChange = (tab: string): void => {
29 + startTransition(() => {
30 + addTransitionType(TOGGLE_TAB_TRANSITION);
31 + onTabChange(tab);
32 + });
33 + };
34 +
35 return (
36 <div className="flex-1 min-w-[550px] sm:min-w-0">
37 <div className="flex flex-col h-full max-w-full">
@@ -25,13 +41,29 @@ export default function TabbedWindow({
41 return (
42 <button
43 key={tab}
28 - onClick={() => onTabChange(tab)}
44 + onClick={() => handleTabChange(tab)}
45 className={clsx(
30 - 'active:scale-95 transition-transform py-1.5 px-1.5 xs:px-3 sm:px-4 rounded-full text-sm',
31 - !isActive && 'hover:bg-primary/5',
32 - isActive && 'bg-highlight text-link',
46 + 'transition-transform py-1.5 px-1.5 xs:px-3 sm:px-4 rounded-full text-sm relative',
47 + isActive ? 'text-link' : 'hover:bg-primary/5',
48 )}>
34 - {tab}
49 + {isActive && (
50 + <ViewTransition
51 + name={transitionName}
52 + share={{
53 + [TOGGLE_TAB_TRANSITION]: 'tab-highlight',
54 + default: 'none',
55 + }}
56 + update={{default: 'none'}}>
57 + <div className="absolute inset-0 bg-highlight rounded-full" />
58 + </ViewTransition>
59 + )}
60 + <ViewTransition
61 + update={{
62 + [TOGGLE_TAB_TRANSITION]: 'tab-text',
63 + default: 'none',
64 + }}>
65 + <span className="relative z-1">{tab}</span>
66 + </ViewTransition>
67 </button>
68 );
69 })}
compiler/apps/playground/lib/transitionTypes.ts
+1
@@ -6,3 +6,4 @@
6 */
7
8 export const CONFIG_PANEL_TRANSITION = 'config-panel';
9 +export const TOGGLE_TAB_TRANSITION = 'toggle-tab';
compiler/apps/playground/styles/globals.css
+8
@@ -108,3 +108,11 @@
108 object-fit: none;
109 object-position: left;
110 }
111 +
112 +::view-transition-old(.tab-highlight),
113 +::view-transition-new(.tab-highlight) {
114 + height: 100%;
115 +}
116 +::view-transition-group(.tab-text) {
117 + z-index: 1;
118 +}