Fix void element bug and add key parameter to replace method#16
Merged
remarkablemark merged 4 commits intomasterfrom Aug 29, 2016
Merged
Fix void element bug and add key parameter to replace method#16remarkablemark merged 4 commits intomasterfrom
key parameter to replace method#16remarkablemark merged 4 commits intomasterfrom
Conversation
The error came from the fact that `props.children` would always
be at minimum an empty array `[]`.
This causes the following error:
```js
ReactDOMServer.renderToString(
Parser('<img />')
);
// Invariant Violation: img is a void element tag and must neither
// have `children` nor use `dangerouslySetInnerHTML`.
```
The fix was to make `props.children` equal to `null` unless
there were actually more DOM nodes inside the array.
Add tests to confirm that void HTML element tags no longer throws
an error.
`render` is an alias for `ReactDOMServer.renderToStaticMarkup` Update `render` function to check that the first argument is a valid React element; otherwise, throw an error.
The `replace` method now has 2 parameters: 1. domNode - The object describing the DOM node. 2. key - The array index. The `key` parameter was added because if the element had siblings, then the replaced React element should have a unique "key" prop or else React will display a warning: > Warning: Each child in an array or iterator should have a > unique "key" prop. See https://fb.me/react-warning-keys for > more information. Updated the mock data for complex html and used the `key` parameter to fix a test.
Add new parameter `key` and update examples.
This was referenced Aug 29, 2016
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14
Bug:
<img>into DOM nodes like below:React.createElement('img', {}, [])is called, it gives the following error:Fix:
childrenremainsnullFeatures:
keyas the 2nd parameter to replace. This ensures that the React key warning does not come up.Chore:
README.mdwith updated instructions and examples onreplace