Skip to content

Commit b5a33e9

Browse files
committed
feat: support ssr
1 parent cfe21aa commit b5a33e9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/QueueAnim.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { createElement } from 'react';
22
import PropTypes from 'prop-types';
33
import TweenOne, { ticker } from 'rc-tween-one';
44
import { polyfill } from 'react-lifecycles-compat';
5+
import { windowIsUndefined } from './utils';
56

67
import {
78
toArrayChildren,
@@ -73,7 +74,7 @@ class QueueAnim extends React.Component {
7374
const leaveChild = children.filter(
7475
item => item && $self.keysToLeave.indexOf(item.key) >= 0,
7576
);
76-
77+
7778
$self.leaveUnfinishedChild = leaveChild.map(item => item.key);
7879
/**
7980
* 获取 leaveChild 在 state.children 里的序列,再将 leaveChild 和 currentChildren 的重新排序。
@@ -546,6 +547,9 @@ class QueueAnim extends React.Component {
546547
appear,
547548
...tagProps
548549
} = this.props;
550+
if (windowIsUndefined) {
551+
return createElement(component, { ...tagProps, ...componentProps }, this.props.children);
552+
}
549553
const childrenToRender = toArrayChildren(this.state.children).map(this.getChildrenToRender);
550554
const props = {
551555
...tagProps,

src/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* eslint no-prototype-builtins: 0 */
22
import React from 'react';
33

4+
export const windowIsUndefined = !(
5+
typeof window !== 'undefined' &&
6+
window.document &&
7+
window.document.createElement
8+
);
9+
410
export function toArrayChildren(children) {
511
const ret = [];
612
React.Children.forEach(children, c => {

0 commit comments

Comments
 (0)