Skip to content
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

Add test for warning for camelCased unknown props #10612

Conversation

flarnie
Copy link
Contributor

@flarnie flarnie commented Sep 5, 2017

what is the change?:
When we render unknown props, they get converted to lower-case.

This may be unexpected for people, or break what they are expecting to
happen. Let's warn in this case and ask them to explicitly pass the
lower-cased attribute name.

why make this change?:
To avoid corner case buggy results for users.

test plan:
NOTE: ~~~It does NOT pass right now. This is a known issue.
Should we change and just expect a warning, but allow the attribute
value to be set?

yarn run test src/renderers/dom/shared/__tests__/ReactDOMAttribute-test.js

issue: #10399

**what is the change?:**
When we render unknown props, they get converted to lower-case.

This may be unexpected for people, or break what they are expecting to
happen. Let's warn in this case and ask them to explicitly pass the
lower-cased attribute name.

**why make this change?:**
To avoid corner case buggy results for users.

**test plan:**
NOTE: ~~~It does NOT pass right now. This is a known issue.
Should we change and just expect a warning, but allow the attribute
value to be set?

`yarn run test src/renderers/dom/shared/__tests__/ReactDOMAttribute-test.js`

**issue:** facebook#10399
@nhunzaker
Copy link
Contributor

@flarnie do you mind if I push commits to fix this test?

@nhunzaker
Copy link
Contributor

nhunzaker commented Sep 5, 2017

Oof. (edit: requiring lowercase) breaks a lot of tests that send in things like fooBar. Away I go!

@nhunzaker
Copy link
Contributor

Should we change and just expect a warning, but allow the attribute value to be set?

Before I change quite a few tests, I'd vote we simply warn. What are other opinions? cc @sebmarkbage @gaearon (feel free to CC anyone else)

@flarnie
Copy link
Contributor Author

flarnie commented Sep 6, 2017

@flarnie do you mind if I push commits to fix this test?

That would be great, and I agree we should decide on the desired behavior before jumping in.

Before I change quite a few tests, I'd vote we simply warn. What are other opinions? cc @sebmarkbage @gaearon (feel free to CC anyone else)

I think it would be ok to just warn, but also would like to get @sebmarkbage's opinion since he brought up this concern in the first place.

@sebmarkbage
Copy link
Collaborator

Even if we warn we wouldn't want the tests to trigger the warning so we should just fix the tests. (Unless the tests are actually testing something related to this.)

I think we should make this a hard console.error because we'd want to be able to change the behavior of these without requiring a major release. (For example, if one of them becomes known.)

@sebmarkbage
Copy link
Collaborator

This one seems to explicitly test this but that seems odd:

const e = await render(<div fooBar="test" />);
expect(e.getAttribute('fooBar')).toBe('test');

This shouldn't pass...?

@sebmarkbage
Copy link
Collaborator

Oh I see, I guess the getAttribute itself is case-insensitive for HTML so it works. But element.attributes[0].name is lower-case.

@sebmarkbage
Copy link
Collaborator

Maybe this is isn't so important for HTML after all? Maybe it's just important for SVG? I forget why this came up last week. We could probably punt on this until after 16.0.

@sebmarkbage
Copy link
Collaborator

I think it might be enough to have this warning in SVG but that's very edge-casey so we could add it later if we don't want to block.

@nhunzaker
Copy link
Contributor

I think it might be enough to have this warning in SVG but that's very edge-casey so we could add it later if we don't want to block.

I'm on board with this. At this point, ReactDOMUnknownPropertyHook could use a refactor. The interaction between it, ReactDOMFiberComponent, and others pieces feels ripe for it. It would be great to revisit how we track what is an HTML, SVG, custom attribute, etc, and rethink these validations with less of a constraint on time and without the burden of the Stack renderer.

@gaearon
Copy link
Collaborator

gaearon commented Sep 6, 2017

Yes, I think it was only important for SVG.


var el = document.createElement('div');
ReactDOM.render(<div hELLo="something" />, el);
expect(el.firstChild.hasAttribute('hELLo')).toBe(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if we add this warning I don't think we plan to strip them. Rather, we'll warn but leave them in the DOM.

@gaearon
Copy link
Collaborator

gaearon commented Sep 13, 2017

I sent a PR for this in #10699.

@gaearon gaearon closed this Sep 28, 2017
@flarnie flarnie deleted the addTestForWarningOnCamelCasedUnknownAttributes branch May 25, 2018 17:51
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.

5 participants