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

Server rendered views 'flash' #1

Closed
KieranGreenwood opened this issue Apr 3, 2016 · 6 comments
Closed

Server rendered views 'flash' #1

KieranGreenwood opened this issue Apr 3, 2016 · 6 comments

Comments

@KieranGreenwood
Copy link

If react is rendered on the server, the page is displayed, then flashes as the initial style is set to 0 opacity, then animated back in.

Is there any way to negate this?

@misterfresh
Copy link
Owner

You could check in your code if the window object is present, and if it is not, disable the transition effect. To do that, you can just edit the javascript object that holds the transition styles, which is one more advantage of not dealing with a css rule.

@KieranGreenwood
Copy link
Author

I did try something similar but as soon as react is picked up on the client, window/document become available so the styles are re-animated from static.

Example:

var initialStyle = typeof window !== 'undefined' ? {opacity: 0} : {opacity: 1};
...
<EasyTransition
    path={path.path + 'path'}
    initialStyle={initialStyle}
     transition="opacity 0.3s ease-in"
    finalStyle={{opacity: 1}}
>
{this.props.children}
</EasyTransition>

I've also tried disabling it for the first initial load/refresh like so, but this stops routing working all together with no errors.

constructor() {
    super();
    this.state = { initialStyle: { opacity: 1 } }
}

componentDidMount() {
    this.setState({initialStyle: {opacity: 0}})
}

//render....
<EasyTransition
    path={path.path + 'path'}
    initialStyle={this.state.initialStyle}
     transition="opacity 0.3s ease-in"
    finalStyle={{opacity: 1}}
>
{this.props.children}
</EasyTransition>

@misterfresh
Copy link
Owner

How about something like that :
//in render method

{(typeof window !== 'undefined' &&
                window.document && window.document.createElement) ?
                <EasyTransition
                    path={path}
                    initialStyle={initialStyle}
                    transition="opacity 0.3s ease-in"
                    finalStyle={finalStyle}
                >
                    {this.props.children}
                </EasyTransition> :
                    this.props.children
                }

@KieranGreenwood
Copy link
Author

This gives the same behaviour as above because.as soon as its loaded client side, the expression evaluates to true so <EasyTransition> overwrites the server rendered this.props.children and animates them back in.

What I need is a way for the client to not run it on initial load, which is what i've attempted by setting the initialStyle to the same as the finalStyle to give the illusion of no animation, then update the state of initialStyle to opacity: 0 on mount so that the following route changes animate based on the intented initialStyle.

If that makes sense.

@misterfresh
Copy link
Owner

Thanks for reporting the problem, I'll look into it and let you know if I find a solution.

@misterfresh
Copy link
Owner

@Kiee fixed it in the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants