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

Refactor DOM attribute code (take two) #11815

Merged
merged 31 commits into from
Dec 10, 2017
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Dec 8, 2017

Re-submit of #11804 which I reverted.

There's still a bug here. shouldTreatAsNull is the wrong way to think about it because this causes booleans that default to true to become false whereas our intention is to ignore them for functions/symbols.

I'll need to look at this again and figure out how to fix this.

Mostly, this is a refactoring, but it does fix some edge cases where SSR used to crash (such as with Symbols) but now warns, consistently with the client.

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 10, 2017

The latest bench looks neutral to me. I added refactoring of the whitelists, inspired by #11733 but without the slowness.

screen shot 2017-12-10 at 03 15 34

screen shot 2017-12-10 at 03 15 04

screen shot 2017-12-10 at 03 15 14

screen shot 2017-12-10 at 03 15 19

@gaearon gaearon force-pushed the dom-injection-3 branch 2 times, most recently from 5275a65 to 97c3708 Compare December 10, 2017 12:46
I noticed some patterns weren't being tested.
The branching before the call is unnecessary because setValueForProperty() already
has an internal branch that delegates to deleteValueForProperty() for null and
undefined through the shouldIgnoreValue() check.

The goal is to start unifying these methods because their separation doesn't
reflect the current behavior (e.g. for unknown properties) anymore, and obscures
what actually happens with different inputs.
Now we don't read propertyInfo twice in this case.

I also dropped a few early returns. I added them a while ago when we had
Stack-only tracking of DOM operations, and some operations were being
counted twice because of how this code is structured. This isn't a problem
anymore (both because we don't track operations, and because I've just
inlined this method call).
The special cases for null and undefined already exist in setValueForAttribute().
Their naming is pretty confusing by now. For example setValueForProperty()
calls setValueForAttribute() when shouldSetAttribute() is false (!). I want
to refactor (as in, inline and then maybe factor it out differently) the relation
between them. For now, I'm consolidating the callers to use setValueForProperty().
The naming of these methods is still very vague and conflicting in some cases.
Will need further work.
This makes the flow clearer in my opinion.
It was previously duplicated.

It's also suspiciously similar in purpose to shouldTreatAttributeValueAsNull()
so I want to see if there is a way to unify them.
Its naming was confusing and it was used all over the place instead of more specific checks.
Now that we only have one call site, we might as well inline and get rid of it.
They weren't being properly skipped because of the early return.
I added tests for this case.
I think this PR looks worse on benchmarks because we have to read propertyInfo in different places.
Originally I tried to get rid of propertyInfo, but looks like it's important for performance after all.

So now I'm going into the opposite direction, and precompute propertyInfo as early as possible, and then just pass it around.
This way we can avoid extra lookups but keep functions nice and modular.
It always exists because this function is only called for known properties.
I wrote this and then got confused myself.
Since we run these checks for all booleans, might as well remember it.
The changes reflect that SSR doesn't crash with symbols anymore (and just warns, consistently with the client).
Instead of using flags, explicitly group similar attributes/properties.
@gaearon
Copy link
Collaborator Author

gaearon commented Dec 10, 2017

This combines #11804 and #11733 which were both approved.
So I'll consider this approved by extension.

In any case fixing bugs should be easier with the new test and Flow coverage I added. I also think this is easier to follow subjectively as attributes are now split into groups according to how they work.

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.

None yet

2 participants