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

Commit e8faa8c

Browse files
germanattanasiochrisdhanaraj
authored andcommitted
fix(server-side): fixes server-side rendering (#41)
* 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
1 parent bda7ba6 commit e8faa8c

File tree

8 files changed

+234
-193
lines changed

8 files changed

+234
-193
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ If you want to help improve the docs, it's a good idea to let others know what y
3333

3434
### Setup
3535

36-
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.
36+
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.
3737

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

4040
```
41-
$ git clone git@github.ibm.com:{ YOUR_USERNAME }/bluemix-components-react.git
42-
$ cd bluemix-components-react
41+
$ git clone [email protected]:{ YOUR_USERNAME }/carbon-components-react.git
42+
$ cd carbon-components-react
4343
```
4444

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

47-
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`:
47+
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`:
4848

4949
```
50-
$ git remote add upstream git@github.ibm.com:Bluemix/bluemix-components-react.git
50+
$ git remote add upstream [email protected]:carbon-design-system/carbon-components-react.git
5151
$ git remote -v
5252
```
5353

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

94-
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".
95-
96-
![pull request](https://uploads.github.ibm.com/github-enterprise-assets/0000/0076/0000/9135/2dadf224-ca8e-11e5-8eba-bdbe6d698b08.png)
94+
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".
9795

9896
8. Write a title and description, the click "Create pull request".
99-
100-
![write pull request](https://uploads.github.ibm.com/github-enterprise-assets/0000/0076/0000/9126/099cd824-ca88-11e5-89d7-94458a4d9ae3.png)
10197

10298
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.
10399

components/DetailPageHeader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
22
import React, { Component, Children } from 'react';
33
import classnames from 'classnames';
44
import debounce from 'lodash.debounce';
5+
import window from 'window-or-global';
56

67
class DetailPageHeader extends Component {
78
static propTypes = {
@@ -30,7 +31,7 @@ class DetailPageHeader extends Component {
3031

3132
componentDidMount() {
3233
const debouncedScroll = debounce(this.handleScroll, 25);
33-
window.addEventListener('scroll', debouncedScroll); // eslint-disable-line no-undef
34+
window.addEventListener('scroll', debouncedScroll);
3435
}
3536

3637
componentWillReceiveProps(nextProps) {
@@ -44,13 +45,13 @@ class DetailPageHeader extends Component {
4445
}
4546

4647
componentWillUnmount() {
47-
window.removeEventListener('scroll', this.handleScroll); // eslint-disable-line no-undef
48+
window.removeEventListener('scroll', this.handleScroll);
4849
}
4950

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

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

5556
if (currentPosition > 86) {
5657
if (currentPosition > lastPosition) {

components/InteriorLeftNav.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import PropTypes from 'prop-types';
2-
/* global window */
3-
42
import React, { Component } from 'react';
53
import classnames from 'classnames';
4+
import window from 'window-or-global';
5+
66
import InteriorLeftNavList from './InteriorLeftNavList';
77
import InteriorLeftNavItem from './InteriorLeftNavItem';
88
import Icon from './Icon';
@@ -20,7 +20,7 @@ class InteriorLeftNav extends Component {
2020
};
2121

2222
state = {
23-
activeHref: this.props.activeHref || window.location.pathname,
23+
activeHref: this.props.activeHref || (window.location && window.location.pathname),
2424
open: true,
2525
};
2626

components/__tests__/Loading-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global window */
21

32
import React from 'react';
43
import Loading from '../Loading';

internal/FloatingMenu.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4+
import window from 'window-or-global';
45

56
class FloatingMenu extends React.Component {
67
static propTypes = {
@@ -56,7 +57,7 @@ class FloatingMenu extends React.Component {
5657
positionFloatingMenu = () => {
5758
const menuOffset = this.props.menuOffset;
5859

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

6162
const {
6263
left: refLeft,

internal/OptimizedResize.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// mdn resize function
2+
import window from 'window-or-global';
23

34
const OptimizedResize = (function optimizedResize() {
45
const callbacks = [];
@@ -17,7 +18,7 @@ const OptimizedResize = (function optimizedResize() {
1718
function resize() {
1819
if (!running) {
1920
running = true;
20-
window.requestAnimationFrame(runCallbacks); // eslint-disable-line no-undef
21+
window.requestAnimationFrame(runCallbacks);
2122
}
2223
}
2324

@@ -35,7 +36,7 @@ const OptimizedResize = (function optimizedResize() {
3536
// public method to add additional callback
3637
add: (callback) => {
3738
if (!callbacks.length) {
38-
window.addEventListener('resize', resize); // eslint-disable-line no-undef
39+
window.addEventListener('resize', resize);
3940
}
4041
addCallback(callback);
4142
return {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"dependencies": {
8989
"classnames": "2.2.5",
9090
"lodash.debounce": "^4.0.8",
91+
"window-or-global": "^1.0.1",
9192
"react-addons-css-transition-group": "^15.4.2",
9293
"warning": "3.0.0"
9394
},

0 commit comments

Comments
 (0)