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

Fast hydration & FIX iframes hydration #4309

Closed
wants to merge 24 commits into from
Closed

Conversation

avi
Copy link

@avi avi commented Jan 23, 2020

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR relates to an outstanding issue, so please reference it in your PR, or create an explanatory one for discussion. In many cases features are absent for a reason.
  • This message body should clearly illustrate what problems it solves. If there are related issues, remember to reference them.
  • Ideally, include a test that fails without this PR but passes with it. PRs will only be merged once they pass CI. (Remember to npm run lint!)

Tests

  • Run the tests tests with npm test or yarn test)

Solution to #4308

Reuse dom nodes in hydration avoid insertBefore/append dom nodes
Better performance in hydration which is now slower than client side render and avoid reloading iframes...

@avi avi requested a review from Rich-Harris January 23, 2020 15:38
@avi avi changed the title Fast hydration Fast hydration & FIX iframes hydration Jan 26, 2020
@avi avi requested a review from Conduitry January 26, 2020 10:46
@yotambarzilay
Copy link

@Conduitry @Rich-Harris
any chance for this PR to get reviewed?

@devinrhode2
Copy link

These commits should obviously be rebased. At least a vanilla git rebase should do away with all the merge commits. The "remove comment" and "removed console.log" probably should be rebased away. (btw, this is how I personally would perform that particular "rebase" https://gist.github.com/devinrhode2/1dea188a754029c363b85ee2b13acd1c

@sandrina-p
Copy link

sandrina-p commented Feb 13, 2020

This would also fix (probably) sveltejs/sapper#1088!

Edit: I just tested the fork and it fixed the hydratation problem! 😍

});

assert(iframeMutations.length === 0, 'iframe added/removed');
// assert(false, 'test')
Copy link
Member

Choose a reason for hiding this comment

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

Probably comments should be cleared up.

@@ -3,6 +3,8 @@ export default {
name: 'world'
},

skip: true,
Copy link
Member

Choose a reason for hiding this comment

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

Are these tests being skipped?

Copy link
Author

Choose a reason for hiding this comment

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

A couple of tests are skipped - the tests we're written as if their test harness was async but it wasn't and when I wanted to write a test that actually had to be async - the tests failed when I changed the test harness to be async... the change that broke the tests I skipped was to test/hydration/index.js

@antony
Copy link
Member

antony commented Mar 18, 2020

@avi thanks for this - I've done an initial pre-review (as best I can) and I'll see if somebody who is more familiar with this part of the code can do a fuller review.

There were just a couple of bits that confused me so I've added comments.

Copy link
Member

@tanhauhau tanhauhau left a comment

Choose a reason for hiding this comment

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

first of all, @avi thanks for the change.

i think this MR tries to change too many things:

  • skip removing attribute during hydration (which i think its a breaking change)
  • upgrading typescript (probably do it in a separate mr?)
  • skip appendChild if is hydrating (i think this is the one that fix the iframe hydration reloading bug)
    • if claiming will insert the element into the DOM, i think we can skip mounting if hydrate right?
  • fix hydration of text nodes (i think can do it in separate PR too)

@avi
Copy link
Author

avi commented Mar 19, 2020

I know skipping removing attributes is a breaking change, I wanted feedback whether to make my changes behind a compiler flag or not... But the current state of hydration is worse than resetting the innerHtml of the mount point by target.innerHTML = '' and doing client side rendering.
Resetting the attributes causes the src of the iframe to be removed and re-added which also causes the iframe content to reload, it also causes all the bugs with css animations replaying on hydration.
Regarding the skipping of appendChild the old code grabbed DOM nodes regardless of their order (only checking type) which kinda forces the appendChild to be used to reinsert them back in order.
Mounting is still required to attach event handlers etc
I can revert the typescript change
The rest is kinda the atomic unit of change that solves the bug and doesn't introduce new ones.

@avi
Copy link
Author

avi commented Mar 25, 2020

Reverted the typescript bump and resolved a conflict

if (n.nodeType === 3) {
return claim_text(nodes, (n as Text).data);
} else {
return claim_element(nodes, n.nodeName, n, n.namespaceURI !== 'http://www.w3.org/1999/xhtml');
Copy link
Member

Choose a reason for hiding this comment

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

'http://www.w3.org/1999/xhtml' could be replaced with namespaces.html:

export const html = 'http://www.w3.org/1999/xhtml';

this.n = this.n.map(n => {
if (n.nodeType === 3) {
return claim_text(nodes, (n as Text).data);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

it looks like this line and the closing curly brace two lines later both have an extra space

@kjmph
Copy link

kjmph commented Oct 30, 2020

Is there anything that can be done to help move this PR along? Some of the small comments could be fixed fairly quickly.

@benmccann
Copy link
Member

It's probably not that easy. There's more discussion on the linked issue: #4308

@jonatansberg
Copy link

Yeah, I tried to rebase this the other day, and a whole lot of tests are failing.

@benmccann
Copy link
Member

benmccann commented Oct 30, 2020

When I said it wouldn't be that easy, I meant that just rebasing this PR probably wouldn't be enough to get it checked in since there's not agreement that this is the right approach. I wasn't commenting on how hard or easy it would be to rebase and didn't expect any particular difficulties there.

@benmccann
Copy link
Member

I just saw your comment on the issue from yesterday - yeah if you can do it without breaking changes that seems more likely to be accepted to me - but it might be good to ask some other folks as well to get sign-off on the approach before sinking too much time

@jonatansberg
Copy link

@benmccann Yeah, sorry, my comment above was a bit inexplicit. Currently on my phone..

What I meant to say above was that even just getting this to a point where everything works (with or without rebasing) would still require more work. The whole debate of the suitability of this approach notwithstanding.

I’m trying to get a slight variation of the approach taken by @avi to work, but I keep running in to issues.

@benmccann
Copy link
Member

Addressed in #6204. Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants