question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSR and <Fade> : Prop `style` did not match

See original GitHub issue

Hello,

I want to surround a component with <Fade> only when on client side. So here is what my code look like :

import React from 'react';
import {Fade} from '@material-ui/core';

const isServer = function() {
    return !(
        typeof window !== 'undefined' &&
        window.document &&
        window.document.createElement
    );
};

class MyComponent extends React.Component {
    render() {
        const content = (
            <div>Hello</div>
        );

        if (isServer()) {
            return content;
        }

        return (
            <Fade in={true} timeout={2500} mountOnEnter unmountOnExit>
                {content}
            </Fade>
        );
    }
}

export default MyComponent;

This code generate the following warning on the client-side console :

Warning: Prop style did not match. Server: “null” Client: “opacity:0;will-change:opacity”

How can I avoid this ?

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Oct 31, 2018

@remigarcia It’s a React issue, you can’t do that. I can share with you two helpers:

NoSrr https://material-ui.com/utils/no-ssr/

SrrOnly.js the opposite of NoSrr

let reconciled = true

class SsrOnly extends React.Component {
  componentDidMount() {
    reconciled = false
  }

  render() {
    return reconciled ? this.props.children : true
  }
}

SsrOnly.propTypes = {
  children: PropTypes.node.isRequired,
}

If your issue is with the first animation, use <Fade appear={false}>.

1reaction
oliviertassinaricommented, Nov 2, 2018

@remigarcia From my understanding, react-transition-group can be configured for your SSR use case. Just have to dig into the right properties combination. The Fade do support it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSR and <Fade> : Prop `style` did not match · Issue #13471
Hello, I want to surround a component with only when on client side. So here is what my code look like : import...
Read more >
Next.js, why? Warning: Prop `style` did not match. Server ...
As some people had the same issue as you do, you can try two things : Import Your component a different way, without...
Read more >
Warning: Prop className did not match-Reactjs
The problem is the SSR rendering in Next.js, which produces the style fragment before the page is rendered. Using Material UI and Next.js...
Read more >
Docs • Svelte
Complete documentation for Svelte.
Read more >
Tag: Server-side Rendering - somewhat abstract
Console output showing warning that says "Prop 'src' did not match" along Hydration error in React 17.0. This is from React 17, though...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found