Skip to content

feat(react-motion): add replayKey prop to replay motion without remounting#36108

Open
robertpenner wants to merge 6 commits intomicrosoft:masterfrom
robertpenner:feat/motion-component-replay-key
Open

feat(react-motion): add replayKey prop to replay motion without remounting#36108
robertpenner wants to merge 6 commits intomicrosoft:masterfrom
robertpenner:feat/motion-component-replay-key

Conversation

@robertpenner
Copy link
Copy Markdown
Collaborator

@robertpenner robertpenner commented May 6, 2026

  • Add an optional replayKey prop to MotionComponentProps.
  • When the value changes, the animation effect re-runs — cancelling any in-progress animation and replaying from the start on the same DOM element, without remounting the component or its children.
  • Includes tests verifying both replay behaviour and DOM continuity.
  • Adds a Storybook story with a side-by-side before/after demo.
image

Previous Behavior

To retrigger a motion animation on an already-mounted component, the only declarative option was to change the React key prop, which forces a full unmount and remount of the subtree. This destroys the DOM nodes, resets child component state, and loses focus — even when all you want is to replay the animation.

New Behavior

MotionComponent accepts an optional replayKey prop (string | number). When the value changes, the animation replays from the beginning on the existing DOM element — cancelling any in-progress animation — without unmounting or remounting the component or its children. DOM continuity, focus, and child state are all preserved.

const [replayKey, setReplayKey] = React.useState(0);

<Fade.In replayKey={replayKey}>
  <div>Content</div>
</Fade.In>
<button onClick={() => setReplayKey(k => k + 1)}>Replay</button>

Future Work

@robertpenner robertpenner self-assigned this May 6, 2026
@robertpenner robertpenner force-pushed the feat/motion-component-replay-key branch from dd35075 to 0967549 Compare May 6, 2026 05:57
@robertpenner robertpenner force-pushed the feat/motion-component-replay-key branch from 0967549 to 864d814 Compare May 7, 2026 14:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-accordion
Accordion (including children components)
92.107 kB
29.097 kB
92.121 kB
29.108 kB
14 B
11 B
react-charts
AreaChart
402.548 kB
125.863 kB
402.562 kB
125.878 kB
14 B
15 B
react-charts
DeclarativeChart
753.304 kB
220.052 kB
753.318 kB
220.062 kB
14 B
10 B
react-charts
DonutChart
312.961 kB
96.495 kB
312.975 kB
96.506 kB
14 B
11 B
react-charts
FunnelChart
304.508 kB
93.326 kB
304.522 kB
93.34 kB
14 B
14 B
react-charts
GanttChart
385.649 kB
120.152 kB
385.663 kB
120.16 kB
14 B
8 B
react-charts
GaugeChart
312.394 kB
95.948 kB
312.408 kB
95.955 kB
14 B
7 B
react-charts
GroupedVerticalBarChart
393.525 kB
122.894 kB
393.539 kB
122.904 kB
14 B
10 B
react-charts
HeatMapChart
387.728 kB
121.263 kB
387.742 kB
121.276 kB
14 B
13 B
react-charts
HorizontalBarChart
292.691 kB
89.04 kB
292.705 kB
89.055 kB
14 B
15 B
react-charts
Legends
232.228 kB
69.849 kB
232.242 kB
69.857 kB
14 B
8 B
react-charts
LineChart
413.882 kB
128.765 kB
413.896 kB
128.773 kB
14 B
8 B
react-charts
PolarChart
341.357 kB
106.417 kB
341.371 kB
106.425 kB
14 B
8 B
react-charts
SankeyChart
209.97 kB
67.042 kB
209.984 kB
67.056 kB
14 B
14 B
react-charts
ScatterChart
393.264 kB
122.86 kB
393.278 kB
122.868 kB
14 B
8 B
react-charts
VerticalBarChart
430.006 kB
127.714 kB
430.02 kB
127.725 kB
14 B
11 B
react-charts
VerticalStackedBarChart
399.53 kB
124.283 kB
399.544 kB
124.293 kB
14 B
10 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
226.994 kB
68.166 kB
227.008 kB
68.178 kB
14 B
12 B
react-components
react-components: entire library
1.292 MB
324.681 kB
1.292 MB
324.691 kB
14 B
10 B
react-dialog
Dialog (including children components)
91.172 kB
28.31 kB
91.186 kB
28.323 kB
14 B
13 B
react-menu
Menu (including children components)
160.425 kB
50.891 kB
160.439 kB
50.898 kB
14 B
7 B
react-menu
Menu (including selectable components)
163.603 kB
51.535 kB
163.617 kB
51.543 kB
14 B
8 B
react-motion
@fluentui/react-motion - createMotionComponent()
4.156 kB
1.818 kB
4.17 kB
1.829 kB
14 B
11 B
react-motion
@fluentui/react-motion - createPresenceComponent()
5.908 kB
2.442 kB
5.922 kB
2.454 kB
14 B
12 B
react-popover
Popover
123.802 kB
39.735 kB
123.816 kB
39.751 kB
14 B
16 B
react-progress
ProgressBar
20.23 kB
7.866 kB
20.244 kB
7.875 kB
14 B
9 B
react-teaching-popover
TeachingPopover
102.196 kB
32.335 kB
102.21 kB
32.351 kB
14 B
16 B
react-toast
Toast (including Toaster)
92.099 kB
28.662 kB
92.113 kB
28.674 kB
14 B
12 B
react-tree
FlatTree
136.789 kB
40.787 kB
136.803 kB
40.798 kB
14 B
11 B
react-tree
PersonaFlatTree
138.617 kB
41.303 kB
138.631 kB
41.313 kB
14 B
10 B
react-tree
PersonaTree
134.677 kB
40.086 kB
134.691 kB
40.095 kB
14 B
9 B
react-tree
Tree
132.855 kB
39.62 kB
132.869 kB
39.63 kB
14 B
10 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-avatar
Avatar
48.492 kB
15.379 kB
react-avatar
AvatarGroup
17.468 kB
6.999 kB
react-avatar
AvatarGroupItem
61.513 kB
19.251 kB
react-breadcrumb
@fluentui/react-breadcrumb - package
103.889 kB
29.167 kB
react-charts
HorizontalBarChartWithAxis
63 B
83 B
react-charts
Sparkline
80.503 kB
26.644 kB
react-components
react-components: Button, FluentProvider & webLightTheme
67.61 kB
19.536 kB
react-components
react-components: FluentProvider & webLightTheme
40.806 kB
13.616 kB
react-datepicker-compat
DatePicker Compat
214.121 kB
62.046 kB
react-headless-components-preview
react-headless-components-preview: entire library
107.577 kB
31.646 kB
react-message-bar
MessageBar (all components)
23.418 kB
8.651 kB
react-motion
@fluentui/react-motion - PresenceGroup
1.727 kB
823 B
react-overflow
hooks only
11.966 kB
4.565 kB
react-persona
Persona
55.447 kB
17.311 kB
react-portal-compat
PortalCompatProvider
5.567 kB
2.237 kB
react-table
DataGrid
148.07 kB
44.013 kB
react-table
Table (Primitives only)
38.209 kB
12.782 kB
react-table
Table as DataGrid
119.815 kB
33.806 kB
react-table
Table (Selection only)
66.603 kB
19.023 kB
react-table
Table (Sort only)
65.246 kB
18.638 kB
react-tag-picker
@fluentui/react-tag-picker - package
174.546 kB
54.381 kB
react-tags
InteractionTag
13.742 kB
5.473 kB
react-tags
Tag
29.666 kB
9.433 kB
react-tags
TagGroup
71.009 kB
21.901 kB
react-timepicker-compat
TimePicker
105.613 kB
35.351 kB
🤖 This report was generated against 7b586d76279e090d7b459bc4c066bd9804e4f2aa

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Pull request demo site: URL

@robertpenner robertpenner marked this pull request as ready for review May 7, 2026 15:32
@robertpenner robertpenner requested review from a team as code owners May 7, 2026 15:32
@robertpenner robertpenner requested a review from layershifter May 7, 2026 15:32
…nting

Add an optional replayKey prop to MotionComponentProps. When the value
changes, the animation effect re-runs — cancelling any in-progress
animation and replaying from the start on the same DOM element, without
remounting the component or its children. Includes tests verifying both
replay behaviour and DOM continuity.
@robertpenner robertpenner force-pushed the feat/motion-component-replay-key branch from 68ec731 to bc88d21 Compare May 8, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant