Skip to content

Commit ce18916

Browse files
brettgullanbraposo
authored andcommitted
Feature: enable server-side-rendering (#17)
* Conditionally require picturefill to allow SSR * Add can-use-dom * fix: Add canUseDom guard on ieVersion check
1 parent 21b47ad commit ce18916

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"react-dom": "^15.0.1"
7171
},
7272
"dependencies": {
73+
"can-use-dom": "^0.1.0",
7374
"glamorous": "^3.23.3",
7475
"picturefill": "^3.0.2",
7576
"prop-types": "^15.5.10"

src/components/Picture.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import React from "react";
22
import PropTypes from "prop-types";
3-
import picturefill from "picturefill";
43
import glamorous from "glamorous";
4+
import canUseDom from 'can-use-dom'
55

66
const Img = glamorous.img();
77

88
class Picture extends React.PureComponent {
99
componentDidMount() {
10-
picturefill();
10+
// c.f. https://github.com/scottjehl/picturefill/pull/556
11+
var picturefill;
12+
try {
13+
picturefill = require('picturefill');
14+
} catch(x) {}
15+
16+
if (picturefill) picturefill(); // browser
17+
// else node
1118
}
1219

1320
renderSources() {
14-
const ieVersion = document.documentMode ? document.documentMode : -1;
21+
const ieVersion = canUseDom && document.documentMode ? document.documentMode : -1;
1522
const { sources } = this.props;
1623

1724
if (sources == null) {

0 commit comments

Comments
 (0)