Files
react/scripts
Sebastian Markbåge 8d61138186 Warn When The HTML Mismatches in DEV (#10026)
* Warn for text content

* Warn for different attributes/properties values

Warns if there are unknown extra attributes in the hydrated node.

It also tries to compare the existing property or attribute against the
expected value. It does this by reading the property and comparing it to
the prop. Except it's not that simple because multiple prop values can
yield the same output. For this we pass an extra expected value that is
a hint as to which one was used. This is a bit weird but I'm not sure the
alternatives were much better.

* Warn when there is an insertion or deletion during hydration

This warns if there is ever an insertion or deletion due to hydration
failing to find a match.

Currently we can't warn for insertions required into the root because
that's how we do all non-hydrating renders atm. Left a todo.

This strategy is a bit unfortunate that it leads to so much plumbing code.
And we have to add three extra methods to the HostConfig that are only used
in DEV and not for anything else. I don't really have a better idea.

* Don't try to delete children of a textarea

Textareas are special cases. The initial mount inserts children
as the default value, but we should leave that untouched. This is the same
as the special case where we set text content of children so I'll use that
mechanism.

* Change expected format for text differences

In Stack this is presented as HTML which needs to have normalized escaping
rules. In Fiber it is currently not presented as HTML but a raw string
so we don't escape it.

* Unmount component in between tests

In Fiber, the second warning isn't issued because it's considered an update
not a new initial render and we don't fire the warning for those.

* Change expectation of white space text behavior in Fiber

In Fiber we don't expect empty strings to be different from rendering null.
In fact, in a follow up I plan on formalizing this by never creating text
Fibers for empty strings.

* Warn for different dangerouslySetInnerHTML

We can't just compare the raw innerHTML value because it will have been
normalized. Instead, we'll create another element, set its innerHTML and
read it back.

Since there can be custom elements registered with this document, we want
to avoid any side-effects they might cause. So I do this in a fresh new
document.

I'm not sure how this would affect controlled components and other stuff
that could have changed after runtime. I think for those cases maybe we
just need a general way of opting out of the diff.
2017-06-29 19:47:44 -07:00
..
2017-05-18 19:13:59 -04:00
2017-04-20 11:18:33 -07:00
2013-09-09 23:42:54 -07:00