Skip to content

Commit

Permalink
Return early from enqueuePutListener for SSR (#6678)
Browse files Browse the repository at this point in the history
(cherry picked from commit eb11648)
  • Loading branch information
aweary authored and zpao committed May 10, 2016
1 parent b0deadc commit ff3cec5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var ReactDOMSelect = require('ReactDOMSelect');
var ReactDOMTextarea = require('ReactDOMTextarea');
var ReactMultiChild = require('ReactMultiChild');
var ReactPerf = require('ReactPerf');
var ReactServerRenderingTransaction = require('ReactServerRenderingTransaction');

var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
var invariant = require('invariant');
Expand Down Expand Up @@ -207,6 +208,9 @@ function assertValidProps(component, props) {
}

function enqueuePutListener(inst, registrationName, listener, transaction) {
if (transaction instanceof ReactServerRenderingTransaction) {
return;
}
if (__DEV__) {
// IE8 has no API for event capturing and the `onScroll` event doesn't
// bubble.
Expand All @@ -218,10 +222,6 @@ function enqueuePutListener(inst, registrationName, listener, transaction) {
var containerInfo = inst._nativeContainerInfo;
var isDocumentFragment = containerInfo._node && containerInfo._node.nodeType === DOC_FRAGMENT_TYPE;
var doc = isDocumentFragment ? containerInfo._node : containerInfo._ownerDocument;
if (!doc) {
// Server rendering.
return;
}
listenTo(registrationName, doc);
transaction.getReactMountReady().enqueue(putListener, {
inst: inst,
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,12 @@ describe('ReactDOMComponent', function() {
'Warning: This browser doesn\'t support the `onScroll` event'
);
});

it('should not warn when server-side rendering `onScroll`', function() {
spyOn(console, 'error');
ReactDOMServer.renderToString(<div onScroll={() => {}}/>);
expect(console.error).not.toHaveBeenCalled();
});
});

describe('tag sanitization', function() {
Expand Down

0 comments on commit ff3cec5

Please sign in to comment.