@samitouri / QOS-React / commits / eb116482a3

Return early from enqueuePutListener for SSR (#6678)

Brandon Dail committed May 2, 2016 at 16:26 UTC eb116482a34a65c52f7de92493985852371da727
2 files changed +10 -4
src/renderers/dom/shared/ReactDOMComponent.js
+4 -4
@@ -35,6 +35,7 @@ var ReactDOMTextarea = require('ReactDOMTextarea');
35 var ReactInstrumentation = require('ReactInstrumentation');
36 var ReactMultiChild = require('ReactMultiChild');
37 var ReactPerf = require('ReactPerf');
38 +var ReactServerRenderingTransaction = require('ReactServerRenderingTransaction');
39
40 var emptyFunction = require('emptyFunction');
41 var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
@@ -210,6 +211,9 @@ function assertValidProps(component, props) {
211 }
212
213 function enqueuePutListener(inst, registrationName, listener, transaction) {
214 + if (transaction instanceof ReactServerRenderingTransaction) {
215 + return;
216 + }
217 if (__DEV__) {
218 // IE8 has no API for event capturing and the `onScroll` event doesn't
219 // bubble.
@@ -221,10 +225,6 @@ function enqueuePutListener(inst, registrationName, listener, transaction) {
225 var containerInfo = inst._nativeContainerInfo;
226 var isDocumentFragment = containerInfo._node && containerInfo._node.nodeType === DOC_FRAGMENT_TYPE;
227 var doc = isDocumentFragment ? containerInfo._node : containerInfo._ownerDocument;
224 - if (!doc) {
225 - // Server rendering.
226 - return;
227 - }
228 listenTo(registrationName, doc);
229 transaction.getReactMountReady().enqueue(putListener, {
230 inst: inst,
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
+6
@@ -1107,6 +1107,12 @@ describe('ReactDOMComponent', function() {
1107 'Warning: This browser doesn\'t support the `onScroll` event'
1108 );
1109 });
1110 +
1111 + it('should not warn when server-side rendering `onScroll`', function() {
1112 + spyOn(console, 'error');
1113 + ReactDOMServer.renderToString(<div onScroll={() => {}}/>);
1114 + expect(console.error).not.toHaveBeenCalled();
1115 + });
1116 });
1117
1118 describe('tag sanitization', function() {