Skip to content

Fix incorrect DOM when Fragment has siblings#1605

Closed
marvinhagemeister wants to merge 6 commits into
masterfrom
fragment_reordering2
Closed

Fix incorrect DOM when Fragment has siblings#1605
marvinhagemeister wants to merge 6 commits into
masterfrom
fragment_reordering2

Conversation

@marvinhagemeister

@marvinhagemeister marvinhagemeister commented May 5, 2019

Copy link
Copy Markdown
Member

Fixes the issue mentioned in #1593 and #1604 .

Currently a draft because it adds +135 +53 B

EDIT: Didn't rebase against the savings in master when measuring size. Was way off 😅

Also fixes: #1635

Comment thread src/component.js Outdated
Comment thread src/component.js Outdated
sibling = sibling._component && sibling._component._siblingVNode;
}

if (nextDom) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if it's smaller we could do:

parentDom.insertBefore(dom, nextDom || null);

@andrewiggins

Copy link
Copy Markdown
Member

(Thinking out loud) I wonder if it would be smaller to just call diffChildren here... I think this is the only place where we enter our reconcilation through diff instead of diffchildren which leads us to copying what diffchildren does (insert elements into the DOM) here.

Might require creating an intermediate Fragment like top-level render does though

Comment thread src/diff/children.js Outdated
}

if (lastRendered && lastRendered._component) {
lastRendered._component._siblingVNode = childVNode;

@andrewiggins andrewiggins May 8, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add the _sibling pointer to the VNode? Would remove a check and a property access.

// children.js
if (lastRendered) {
	lastRendered._sibling = childVNode;
}
lastRendered = childVNode;
// component.js
let sibling = vnode._sibling;
while (sibling && !(nextDom = sibling._dom)) {
	sibling = sibling._sibling;
}

@marvinhagemeister

Copy link
Copy Markdown
Member Author

Closing because #1689 is an improved version of this PR 🎉

@marvinhagemeister marvinhagemeister deleted the fragment_reordering2 branch June 21, 2019 18:41
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.

10.0.0-beta.1 Incorrect DOM Ordering

4 participants