@samitouri / QOS-React / commits / 9b4e4e1759

Fix obscure error message when passing an invalid style value for SSR (#11173)

* Add failing iframe test * Possible fix by returning null ownerName in SSR * prettier * eslolint * gah c’mon really? * emptyFunction.thatReturnsNull * One less property access

Dustan Kasten committed Oct 10, 2017 at 11:57 UTC 9b4e4e1759353fe51b1c03059cf02f02226a3563
2 files changed +12 -1
src/renderers/dom/shared/__tests__/ReactServerRendering-test.js
+9
@@ -358,6 +358,15 @@ describe('ReactDOMServer', () => {
358 'Objects are not valid as a React child (found: object with keys {x})',
359 );
360 });
361 +
362 + it('should throw prop mapping error for an <iframe /> with invalid props', () => {
363 + expect(() =>
364 + ReactDOMServer.renderToString(<iframe style="border:none;" />),
365 + ).toThrowError(
366 + 'The `style` prop expects a mapping from style properties to values, not ' +
367 + "a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.",
368 + );
369 + });
370 });
371
372 describe('renderToStaticMarkup', () => {
src/renderers/shared/server/ReactPartialRenderer.js
+3 -1
@@ -20,6 +20,7 @@ var ReactControlledValuePropTypes = require('ReactControlledValuePropTypes');
20
21 var assertValidProps = require('assertValidProps');
22 var dangerousStyleValue = require('dangerousStyleValue');
23 +var emptyFunction = require('fbjs/lib/emptyFunction');
24 var emptyObject = require('fbjs/lib/emptyObject');
25 var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
26 var hyphenateStyleName = require('fbjs/lib/hyphenateStyleName');
@@ -29,6 +30,7 @@ var omittedCloseTags = require('omittedCloseTags');
30 var isCustomComponent = require('isCustomComponent');
31
32 var toArray = React.Children.toArray;
33 +var emptyFunctionThatReturnsNull = emptyFunction.thatReturnsNull;
34
35 if (__DEV__) {
36 var warning = require('fbjs/lib/warning');
@@ -780,7 +782,7 @@ class ReactDOMServerRenderer {
782 validatePropertiesInDevelopment(tag, props);
783 }
784
783 - assertValidProps(tag, props);
785 + assertValidProps(tag, props, emptyFunctionThatReturnsNull);
786
787 var out = createOpenTagMarkup(
788 element.type,