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

Split markup generation from DOM property management #10197

Merged
merged 18 commits into from
Jul 19, 2017

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 16, 2017

This forks DOMPropertyOperations into two different files: DOMPropertyOperations is DOM-only and DOMMarkupOperations is SSR-only. This way we don’t have to bundle DOM-only code paths into the SSR renderer. I guess ES6 modules would also help here but I didn’t want to wait. I also rewrote markup-related unit tests as integration tests.

In last few commits I also rewrote tests for CSS properties in public API, and split markup generation (server only), warning about key-value pairs (shared), and setting properties and validation (client-only).

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 16, 2017

This exposed a weird warning:

  console.log src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js:58
    Warning: Prop `download` did not match. Server: "0" Client: 0

Probably a validation bug.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 16, 2017

Should be ready now.

@@ -352,6 +352,11 @@ describe('ReactDOMServerIntegration', () => {
const e = await render(<a href={false} />);
expect(e.getAttribute('href')).toBe('false');
});

itRenders('no string prop with null value', async render => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I only added null cases because others were already handled by existing tests.

);

itRenders('numeric property with zero value', async render => {
const e = await render(<ol start={0} />);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This matters because of #2113. 0 shouldn't be removed in this case.

padding: '4px',
}),
).toBe('left:0;margin:16px;opacity:0.5;padding:4px');
var styles = {
Copy link
Collaborator Author

@gaearon gaearon Jul 18, 2017

Choose a reason for hiding this comment

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

I left a few tests here that specifically assert things about markup (e.g. that it doesn't have extra px or spaces).

Those that only assert correctness are replaced with integration tests.

@@ -90,6 +90,9 @@ var DOMPropertyOperations = {
if (value === '') {
return true;
}
if (value === '' + expected) {
Copy link
Collaborator

@sebmarkbage sebmarkbage Jul 18, 2017

Choose a reason for hiding this comment

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

If expected is null, and the attribute is the string "null" then this should not match.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See the use of shouldIgnoreValue before the equivalent use case below.

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

lgtm but the validation fix is incomplete. see comment.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 18, 2017

I hope 6929d61 fixed this?

Copy link
Contributor

@aickin aickin left a comment

Choose a reason for hiding this comment

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

Looks good to me! Nice job.

var warning = require('fbjs/lib/warning');

// This is currently duplicated with DOMMarkupOperations.
// TODO: Find a better place for this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe include a comment denoting the end of the duplicated code; at first I thought it was just the regex that was duped.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed.

@@ -467,16 +503,44 @@ describe('ReactDOMServerIntegration', () => {
});

// this probably is just masking programmer error, but it is existing behavior.
itRenders('className prop with true value', async render => {
itRenders('htmlFor prop with true value', async render => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, this was almost certainly a copy-paste error on my part. Thanks for fixing it!

@@ -111,6 +114,38 @@ function validateDangerousTag(tag) {
}
}

var processStyleName = memoizeStringOnly(function(styleName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There should probably be a comment here noting that the code here is copied in ReactDOMComponent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll delete it in a few days so probably not worth it.

@gaearon gaearon merged commit 9254ce2 into facebook:master Jul 19, 2017
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.

4 participants