Giter Site home page Giter Site logo

Comments (6)

takacsmark avatar takacsmark commented on May 27, 2024

I added a condition to all occurrences of window in ResponsiveNavigation like this:

import ExecutionEnvironment from 'react/node_modules/fbjs/lib/ExecutionEnvironment'

  componentDidMount() {
      if (ExecutionEnvironment.canUseDOM) {
          window.addEventListener('resize', this.update.bind(this));
      }

  }

  componentWillUnmount() {
      if (ExecutionEnvironment.canUseDOM) {
          window.removeEventListener('resize', this.update.bind(this));
      }
  }


  update() {
    const { breakpoint } = this.props;
    if (ExecutionEnvironment.canUseDOM) {
        this.setState({
          isTitleBarVisible: window.innerWidth < breakpoint,
          isTopBarVisible: window.innerWidth >= breakpoint
        });
    }

This definitely passes server rendering and will work on client side as before. The layout will of course fall apart on the server so it's not a final solution, but it proves the case.

from react-foundation.

crisu83 avatar crisu83 commented on May 27, 2024

While I'm sure that your solution works I would just check if typeof window !== 'undefined'. We could even create a function for this in utils.js.

from react-foundation.

takacsmark avatar takacsmark commented on May 27, 2024

Sounds reasonable, but that would not solve server side rendering of the component. This way there is a FOUC (Flash of unstyled content) when the page is loaded.

from react-foundation.

crisu83 avatar crisu83 commented on May 27, 2024

@takacsmark We've actually also been building an universal React application during the past months so now the SSR is far more familiar to me. AFAIK the FOUC only happens during development, and we fixed it by hiding the content until the assets have been loaded.

We've also noticed that the ResponsiveNavigation component still requires some refactoring for being production ready. How has it worked for you so far apart from this issue?

from react-foundation.

takacsmark avatar takacsmark commented on May 27, 2024

Good to hear you used this part with ssr.
We simplified our functional design for business reasons, and ended up using buttons instead of responsive navigation. So we have not looked into further details regarding ResponsiveNavigation.

from react-foundation.

phoniks avatar phoniks commented on May 27, 2024

Has anyone had success using the typeof window !== 'undefined' solution? I'm trying it (in place of @takacsmark's ExecutionEnvironment.canUseDOM) but getting 'window is not defined'.

from react-foundation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.