Skip to content

View Transition Class Names based on event kind - #32050

Merged
sebmarkbage merged 1 commit into
react:mainfrom
sebmarkbage:viewtransitionclass
Jan 13, 2025
Merged

View Transition Class Names based on event kind#32050
sebmarkbage merged 1 commit into
react:mainfrom
sebmarkbage:viewtransitionclass

Conversation

@sebmarkbage

@sebmarkbage sebmarkbage commented Jan 13, 2025

Copy link
Copy Markdown
Contributor

This adds five props to <ViewTransition> that adds a specific view-transition-class when React wants to animate it based on the heuristic that triggers.

<ViewTransition
  enter="slide-from-left"
  exit="slide-to-right"
  layout="slide"
  update="none"
  share="cross-fade"
>
  • enter: The or its parent Component is mounted and there's no other with the same name being deleted.
  • exit: The or its parent Component is unmounted and there's no other with the same name being deleted.
  • layout: There are no updates to the content inside this boundary itself but the boundary has resized or moved due to other changes to siblings.
  • share: This is being mounted and another instance with the same name is being unmounted elsewhere.
  • update: The content of has changed either due to DOM mutations or because an inner child has resized.

The existing className is the baseline and the others are added to it to combine.

This is convenient to distinguish things like enter / exit but that can already be expressed as CSS. The other cases can't be expressed as purely CSS.

"none" is a special value that deactivates the view transition name under that condition.

The most important feature of this is that you can now limit View Transitions to only tigger when a particular DOM node is affected, not when just any child updates, by opt-ing out a subtree. This is safer when added to shared parent.

<ViewTransition>
  <div>
     <ViewTransition className="none">
       {children}
     </ViewTransition>
  </div>
</ViewTransition>

This can't be fully expressed using neither just CSS nor the imperative refs API since we need some way to have already removed the view-transition-name when this happens. When you think about the implementation details it might seem a bit strange that you specify the class to none to remove the name but it's really about picking which animation should happen for that case default (undefined), a specific one (class) or none ("none").

@react-sizebot

react-sizebot commented Jan 13, 2025

Copy link
Copy Markdown

Comparing: 540efebcc34357c98412a96805bfd9244d6aa678...6cd24654d6a88c76644a2dffbc99087355144b6f

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 514.24 kB 514.24 kB = 91.73 kB 91.74 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.69% 552.39 kB 556.18 kB +0.46% 98.27 kB 98.72 kB
facebook-www/ReactDOM-prod.classic.js = 595.79 kB 595.79 kB = 104.85 kB 104.85 kB
facebook-www/ReactDOM-prod.modern.js = 586.21 kB 586.21 kB = 103.30 kB 103.30 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-reconciler/cjs/react-reconciler.production.js +0.96% 422.71 kB 426.76 kB +0.74% 68.11 kB 68.61 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.js +0.85% 475.72 kB 479.78 kB +0.61% 75.96 kB 76.42 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.69% 552.39 kB 556.18 kB +0.46% 98.27 kB 98.72 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.production.js +0.67% 567.12 kB 570.91 kB +0.44% 101.88 kB 102.33 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.64% 709.79 kB 714.33 kB +0.59% 111.96 kB 112.62 kB
oss-experimental/react-dom/cjs/react-dom-profiling.profiling.js +0.62% 608.62 kB 612.41 kB +0.45% 106.98 kB 107.46 kB
oss-experimental/react-dom/cjs/react-dom-client.development.js +0.45% 1,022.41 kB 1,027.02 kB +0.35% 171.23 kB 171.82 kB
oss-experimental/react-dom/cjs/react-dom-profiling.development.js +0.44% 1,038.81 kB 1,043.41 kB +0.34% 174.05 kB 174.64 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.development.js +0.44% 1,039.33 kB 1,043.93 kB +0.35% 174.93 kB 175.55 kB
oss-experimental/react-art/cjs/react-art.production.js +0.34% 320.42 kB 321.51 kB +0.40% 54.41 kB 54.63 kB
oss-experimental/react-art/cjs/react-art.development.js +0.23% 612.22 kB 613.60 kB +0.22% 97.44 kB 97.65 kB

Generated by 🚫 dangerJS against 29003b5

"none" is a special value that deactivates the view transition name under
that condition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants