Reduce unnecessary DOM attribute reads#2486
Merged
marvinhagemeister merged 5 commits intomasterfrom Apr 21, 2020
Merged
Conversation
|
Size Change: -8 B (0%) Total Size: 39.3 kB
ℹ️ View Unchanged
|
JoviDeCroock
approved these changes
Apr 20, 2020
Member
JoviDeCroock
left a comment
There was a problem hiding this comment.
That's a really good find! We could make it shorter by just doing if (excessDomChildren) but yes nothing major, awesome work!
andrewiggins
commented
Apr 20, 2020
| expect(style.zIndex.toString()).to.equal(''); | ||
| }); | ||
|
|
||
| it('should remove existing attributes', () => { |
Member
Author
There was a problem hiding this comment.
These tests were under the "style attribute" describe block. I just moved them to the bottom of this file out of the "style" describe block since they don't have anything to do with the style attribute.
| expect(serializeHtml(scratch)).to.equal('<div><span>Bye</span></div>'); | ||
| }); | ||
|
|
||
| it('should not read DOM attributes on render without existing DOM', () => { |
Member
Author
There was a problem hiding this comment.
This is the new test for this PR
developit
approved these changes
Apr 21, 2020
Member
developit
left a comment
There was a problem hiding this comment.
Oh wow, this is a great find. Likely a nontrivial performance win for client side routing and also for our suspense resumption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I think there are 4 different "modes" of diffing that Preact can be in (ignoring things like suspense for now).
!isHydratingcheckrenderwhen the container contains existing DOM. This behavior compares the existing DOM with the specified VNodes including attributes.preact-routerand rendering an entirely new route client side. Preact creates the DOM from scratch. Because the DOM is created entirely from scratch, there are no attributes to be read.This PR fixes a bug where the
attributesproperty was being read in case 4. Since this is a fairly common situation, I figured skipping theattributesread would be beneficial.