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

Commit 6fb1d55

Browse files
committed
Merge pull request #22 from twitter-fabric/patch/shim-for-server-rendering
Shims out Velocity on the server
2 parents 9c0b543 + 50d101d commit 6fb1d55

4 files changed

+15
-4
lines changed

lib/velocity-animate-shim.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Shim to avoid requiring Velocity in Node environments, since it
2+
// requires window. Note that this just no-ops the components so
3+
// that they'll render, rather than doing something clever like
4+
// statically rendering the end state of any provided animations.
5+
if (typeof window !== 'undefined') {
6+
module.exports = require('velocity-animate');
7+
} else {
8+
var Velocity = function () {};
9+
Velocity.velocityReactServerShim = true;
10+
module.exports = Velocity;
11+
}

velocity-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var _ = {
3939
omit: require('lodash/object/omit'),
4040
};
4141
var React = require('react');
42-
var Velocity = require('velocity-animate');
42+
var Velocity = require('./lib/velocity-animate-shim');
4343

4444
var VelocityComponent = React.createClass({
4545
displayName: 'VelocityComponent',

velocity-helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var _ = {
44
isObject: require('lodash/lang/isObject'),
55
};
6-
var Velocity = require('velocity-animate');
6+
var Velocity = require('./lib/velocity-animate-shim');
77

88
var effectCounter = 0;
99

velocity-transition-group.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var _ = {
4040
pluck: require('lodash/collection/pluck'),
4141
};
4242
var React = require('react/addons');
43-
var Velocity = require('velocity-animate');
43+
var Velocity = require('./lib/velocity-animate-shim');
4444

4545
// Internal wrapper for the transitioned elements. Delegates all child lifecycle events to the
4646
// parent VelocityTransitionGroup so that it can co-ordinate animating all of the elements at once.
@@ -110,7 +110,7 @@ var VelocityTransitionGroup = React.createClass({
110110

111111
// Without our custom childFactory, we just get a default TransitionGroup that doesn't do
112112
// anything special at all.
113-
if (!this.constructor.disabledForTest) {
113+
if (!this.constructor.disabledForTest && !Velocity.velocityReactServerShim) {
114114
transitionGroupProps.childFactory = this._wrapChild;
115115
}
116116

0 commit comments

Comments
 (0)