Comments (6)
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.
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.
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.
@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.
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.
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)
- Update links HOT 4
- 'isDisabled' property on buttons does not disable the button HOT 1
- Incorrect grid classes HOT 1
- Can someone bump fbjs => isomorphic-fetch? (due to vulnerabilities w node-fetch) HOT 3
- Documentation website not working HOT 2
- "Components with Bit" link not working HOT 1
- XY Grid grid-x grid-margin-x and grid-margin-y HOT 1
- Abide, or more js lib import HOT 1
- GridContainer full / fluid generates render warning from React
- do not require yarn HOT 2
- prepublish scripts are deprecated HOT 2
- deprecations and outdated / insecure (peer) dependencies HOT 6
- Fix the broken README badges HOT 2
- Out of Date Docs. HOT 5
- Warning message when isColumn prop is set on Column component HOT 1
- Does this work with React Native? HOT 1
- XY grid HOT 3
- XY-Grid Cell drops FlexboxPropTypes HOT 4
- Foundation is undefined HOT 1
- Support for custom breakpoints HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-foundation.