Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ssr should not render string at first #19029

Merged
merged 2 commits into from Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/avatar/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -433,6 +433,7 @@ exports[`renders ./components/avatar/demo/dynamic.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
U
</span>
Expand Down Expand Up @@ -486,6 +487,7 @@ exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
Avatar
</span>
Expand All @@ -507,6 +509,7 @@ exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
Avatar
</span>
Expand Down Expand Up @@ -554,6 +557,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
U
</span>
Expand All @@ -563,6 +567,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
USER
</span>
Expand All @@ -580,6 +585,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
U
</span>
Expand Down
12 changes: 11 additions & 1 deletion components/avatar/index.tsx
Expand Up @@ -29,6 +29,7 @@ export interface AvatarProps {

export interface AvatarState {
scale: number;
mounted: boolean;
isImgExist: boolean;
}

Expand All @@ -40,6 +41,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {

state = {
scale: 1,
mounted: false,
isImgExist: true,
};

Expand All @@ -53,6 +55,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {

componentDidMount() {
this.setScale();
this.setState({ mounted: true });
}

componentDidUpdate(prevProps: AvatarProps) {
Expand Down Expand Up @@ -105,7 +108,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
...others
} = this.props;

const { isImgExist, scale } = this.state;
const { isImgExist, scale, mounted } = this.state;

const prefixCls = getPrefixCls('avatar', customizePrefixCls);

Expand Down Expand Up @@ -144,6 +147,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
WebkitTransform: transformString,
transform: transformString,
};

const sizeChildrenStyle: React.CSSProperties =
typeof size === 'number'
? {
Expand All @@ -160,9 +164,15 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
</span>
);
} else {
const childrenStyle: React.CSSProperties = {};
if (!mounted) {
childrenStyle.opacity = 0;
}

children = (
<span
className={`${prefixCls}-string`}
style={{ opacity: 0 }}
ref={(node: HTMLElement) => (this.avatarChildren = node)}
>
{children}
Expand Down
Expand Up @@ -360,6 +360,7 @@ exports[`ConfigProvider components Avatar configProvider 1`] = `
>
<span
class="config-avatar-string"
style="opacity:0"
/>
</span>
`;
Expand All @@ -370,6 +371,7 @@ exports[`ConfigProvider components Avatar normal 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
/>
</span>
`;
Expand All @@ -380,6 +382,7 @@ exports[`ConfigProvider components Avatar prefixCls 1`] = `
>
<span
class="prefix-Avatar-string"
style="opacity:0"
/>
</span>
`;
Expand Down