Skip to content

fix option update. Fixes #2620 #3817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed

Conversation

yiminghe
Copy link
Contributor

@yiminghe yiminghe commented May 5, 2015

Option update will fail if option's content is mixed with variable and literal text. for example:

https://jsfiddle.net/yiminghe/jw73ccu5/1/

function getChildrenTextContent(tag, children) {
var childrenContent = '';
ReactChildren.forEach(children, function (c) {
if ("production" !== process.env.NODE_ENV) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use if(__DEV__) instead of "production" !== process.env.NODE_ENV

@jimfb
Copy link
Contributor

jimfb commented May 5, 2015

@yiminghe Overall looks good. I'm excited to see this fix! A couple of comments. Also, the linter is unhappy (you can execute npm run lint and fix anything of error severity).

@jimfb jimfb changed the title fix option update. Fixes #3816 fix option update. Fixes #2620 May 5, 2015
@jimfb
Copy link
Contributor

jimfb commented May 5, 2015

Tracking issue in #2620

@@ -23,6 +23,8 @@ var ReactComponentBrowserEnvironment =
var ReactMount = require('ReactMount');
var ReactMultiChild = require('ReactMultiChild');
var ReactPerf = require('ReactPerf');
var ReactChildren = require('ReactChildren');
var ReactElement = require('ReactElement');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: abc sort the requires (there's no lint rule for this)

@sophiebits
Copy link
Collaborator

This logic would actually be better in ReactDOMOption especially since we already have that wrapper, not in ReactDOMComponent.

@@ -775,4 +775,39 @@ describe('ReactDOMComponent', function() {
});
});

describe('option update', function(){
var container = document.createElement('div');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be in a beforeEach so that the container is reinitialized before each spec.

@yiminghe
Copy link
Contributor Author

yiminghe commented May 6, 2015

This is not specific for option (maybe in the future), that's why i add onlyNestTextTags map.

@syranide
Copy link
Contributor

syranide commented May 7, 2015

I would be far less concerned if we simply threw on multiple children, or no longer made <option /> accept children like we did with <textarea /> (but that's probably too late now?). As for this specific implementation, if we ever support components returning a string then <option>Hi <Name /></option> wouldn't work as expected, my point being that this fix is basically a hack. It's current idea of what is printable is not identical to Reacts either. EDIT: Also fragments/arrays isn't accepted right now I think?

@sophiebits
Copy link
Collaborator

@yiminghe I understand. I'd prefer to have the logic in ReactDOMOption because I don't anticipate us adding it for other tags. If we choose to do that in the future, we can look at abstracting it out – but ReactDOMComponent is already very complicated and so we'd like to avoid complicating it unnecessarily. Can you move the code to ReactDOMOption's render function?

var childrenContent = '';
ReactChildren.forEach(children, function (c) {
var childType = typeof c;
if (childType !== 'string' && childType !== 'number') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement would be clearer with the branches swapped.

@sophiebits
Copy link
Collaborator

Actually, #3847 looks closer so I'll follow up with that one instead. Thanks for sending this in.

@sophiebits sophiebits closed this May 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants