Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
fix(server-side): fixes server-side rendering (#41)
Browse files Browse the repository at this point in the history
* fix(server-side): Check that window is defined before using it, resolves #40

docs(contributing): Update contributing with github repo url

fix(server-side): Use window-or-global, resolves #40

* fix(server-side): Move devDependency to dependencies
  • Loading branch information
germanattanasio authored and chrisdhanaraj committed Jun 19, 2017
1 parent bda7ba6 commit e8faa8c
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 193 deletions.
16 changes: 6 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ If you want to help improve the docs, it's a good idea to let others know what y

### Setup

1. Fork the project by navigating to the main [repository](https://github.ibm.com/Bluemix/bluemix-components-react) and clicking the **Fork** button on the top-right corner.
1. Fork the project by navigating to the main [repository](https://github.com/carbon-design-system/carbon-components-react) and clicking the **Fork** button on the top-right corner.

2. Navigate to your forked repository and copy the **SSH url**. Clone your fork by running the following in your terminal:

```
$ git clone git@github.ibm.com:{ YOUR_USERNAME }/bluemix-components-react.git
$ cd bluemix-components-react
$ git clone git@github.com:{ YOUR_USERNAME }/carbon-components-react.git
$ cd carbon-components-react
```

See [GitHub docs](https://help.github.com/articles/fork-a-repo/) for more details on forking a repository.

3. Once cloned, you will see `origin` as your default remote, pointing to your personal forked repository. Add a remote named `upstream` pointing to the main `bluemix-components-react`:
3. Once cloned, you will see `origin` as your default remote, pointing to your personal forked repository. Add a remote named `upstream` pointing to the main `carbon-components-react`:

```
$ git remote add upstream git@github.ibm.com:Bluemix/bluemix-components-react.git
$ git remote add upstream git@github.com:carbon-design-system/carbon-components-react.git
$ git remote -v
```

Expand Down Expand Up @@ -91,13 +91,9 @@ If your issue appears to be a bug, and hasn't been reported, open a new issue. H
$ git push origin { YOUR_BRANCH_NAME }
```

7. In Github, navigate to [Bluemix/bluemix-components-react](https://github.ibm.com/Bluemix/bluemix-components-react) and click the button that reads "Compare & pull request".

![pull request](https://uploads.github.ibm.com/github-enterprise-assets/0000/0076/0000/9135/2dadf224-ca8e-11e5-8eba-bdbe6d698b08.png)
7. In Github, navigate to [carbon-design-system/carbon-components-react](https://github.com/carbon-design-system/carbon-components-react) and click the button that reads "Compare & pull request".

8. Write a title and description, the click "Create pull request".

![write pull request](https://uploads.github.ibm.com/github-enterprise-assets/0000/0076/0000/9126/099cd824-ca88-11e5-89d7-94458a4d9ae3.png)

See [how to write the perfect pull request](https://github.com/blog/1943-how-to-write-the-perfect-pull-request) for more details on writing good PRs.

Expand Down
7 changes: 4 additions & 3 deletions components/DetailPageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React, { Component, Children } from 'react';
import classnames from 'classnames';
import debounce from 'lodash.debounce';
import window from 'window-or-global';

class DetailPageHeader extends Component {
static propTypes = {
Expand Down Expand Up @@ -30,7 +31,7 @@ class DetailPageHeader extends Component {

componentDidMount() {
const debouncedScroll = debounce(this.handleScroll, 25);
window.addEventListener('scroll', debouncedScroll); // eslint-disable-line no-undef
window.addEventListener('scroll', debouncedScroll);
}

componentWillReceiveProps(nextProps) {
Expand All @@ -44,13 +45,13 @@ class DetailPageHeader extends Component {
}

componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll); // eslint-disable-line no-undef
window.removeEventListener('scroll', this.handleScroll);
}

handleScroll = () => {
const { lastPosition } = this.state;

const currentPosition = window.pageYOffset; // eslint-disable-line no-undef
const currentPosition = window.pageYOffset || 0;

if (currentPosition > 86) {
if (currentPosition > lastPosition) {
Expand Down
6 changes: 3 additions & 3 deletions components/InteriorLeftNav.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PropTypes from 'prop-types';
/* global window */

import React, { Component } from 'react';
import classnames from 'classnames';
import window from 'window-or-global';

import InteriorLeftNavList from './InteriorLeftNavList';
import InteriorLeftNavItem from './InteriorLeftNavItem';
import Icon from './Icon';
Expand All @@ -20,7 +20,7 @@ class InteriorLeftNav extends Component {
};

state = {
activeHref: this.props.activeHref || window.location.pathname,
activeHref: this.props.activeHref || (window.location && window.location.pathname),
open: true,
};

Expand Down
1 change: 0 additions & 1 deletion components/__tests__/Loading-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global window */

import React from 'react';
import Loading from '../Loading';
Expand Down
3 changes: 2 additions & 1 deletion internal/FloatingMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import ReactDOM from 'react-dom';
import window from 'window-or-global';

class FloatingMenu extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -56,7 +57,7 @@ class FloatingMenu extends React.Component {
positionFloatingMenu = () => {
const menuOffset = this.props.menuOffset;

const scroll = window.scrollY; // eslint-disable-line no-undef
const scroll = window.scrollY || 0;

const {
left: refLeft,
Expand Down
5 changes: 3 additions & 2 deletions internal/OptimizedResize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// mdn resize function
import window from 'window-or-global';

const OptimizedResize = (function optimizedResize() {
const callbacks = [];
Expand All @@ -17,7 +18,7 @@ const OptimizedResize = (function optimizedResize() {
function resize() {
if (!running) {
running = true;
window.requestAnimationFrame(runCallbacks); // eslint-disable-line no-undef
window.requestAnimationFrame(runCallbacks);
}
}

Expand All @@ -35,7 +36,7 @@ const OptimizedResize = (function optimizedResize() {
// public method to add additional callback
add: (callback) => {
if (!callbacks.length) {
window.addEventListener('resize', resize); // eslint-disable-line no-undef
window.addEventListener('resize', resize);
}
addCallback(callback);
return {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"dependencies": {
"classnames": "2.2.5",
"lodash.debounce": "^4.0.8",
"window-or-global": "^1.0.1",
"react-addons-css-transition-group": "^15.4.2",
"warning": "3.0.0"
},
Expand Down
Loading

0 comments on commit e8faa8c

Please sign in to comment.