Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

723 B
Raw Blame
import { flushSync } from 'react-dom';

/**
 * Runs a state update inside a same-document view transition when supported,
 * so elements sharing a `view-transition-name` morph (position, size, shape)
 * between the two states instead of swapping. Falls back to applying the
 * update directly. Call from user-event handlers only: the update is flushed
 * synchronously so the browser can snapshot the old and new layouts.
 */
export function morphTransition(update: () => void): void {
  if (
    typeof document.startViewTransition !== 'function' ||
    window.matchMedia('(prefers-reduced-motion: reduce)').matches
  ) {
    update();
    return;
  }
  document.startViewTransition(() => {
    flushSync(update);
  });
}