Skip to content

Commit

Permalink
Fix obscure error message when passing an invalid style value for SSR (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
iamdustan authored and gaearon committed Oct 10, 2017
1 parent 45c05c7 commit 9b4e4e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ describe('ReactDOMServer', () => {
'Objects are not valid as a React child (found: object with keys {x})',
);
});

it('should throw prop mapping error for an <iframe /> with invalid props', () => {
expect(() =>
ReactDOMServer.renderToString(<iframe style="border:none;" />),
).toThrowError(
'The `style` prop expects a mapping from style properties to values, not ' +
"a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.",
);
});
});

describe('renderToStaticMarkup', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/renderers/shared/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var ReactControlledValuePropTypes = require('ReactControlledValuePropTypes');

var assertValidProps = require('assertValidProps');
var dangerousStyleValue = require('dangerousStyleValue');
var emptyFunction = require('fbjs/lib/emptyFunction');
var emptyObject = require('fbjs/lib/emptyObject');
var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
var hyphenateStyleName = require('fbjs/lib/hyphenateStyleName');
Expand All @@ -29,6 +30,7 @@ var omittedCloseTags = require('omittedCloseTags');
var isCustomComponent = require('isCustomComponent');

var toArray = React.Children.toArray;
var emptyFunctionThatReturnsNull = emptyFunction.thatReturnsNull;

if (__DEV__) {
var warning = require('fbjs/lib/warning');
Expand Down Expand Up @@ -780,7 +782,7 @@ class ReactDOMServerRenderer {
validatePropertiesInDevelopment(tag, props);
}

assertValidProps(tag, props);
assertValidProps(tag, props, emptyFunctionThatReturnsNull);

var out = createOpenTagMarkup(
element.type,
Expand Down

0 comments on commit 9b4e4e1

Please sign in to comment.