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

(async-loader): Use reference in vnode for current node #1308

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions packages/async-loader/async.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { h, Component } from 'preact';
import { Component, options, h } from 'preact';

const PENDING = {};

export default function async(load) {
let dom;
let old = options.vnode;

// get access to the current DOM node from vnode.
options._diff = (vnode) => {
if (!component && vnode._children) {
let prev;
for (let i = 0; i < vnode._children.length; i++) {
let c = vnode._children[i];
if (c) {
prev = c._dom || c.__e || prev;

if (c.type === AsyncComponent) {
dom = prev.nextSibling;
}
}
}
}
if (old) old(vnode);
};

let component;
function AsyncComponent() {
Component.call(this);
Expand All @@ -23,7 +44,7 @@ export default function async(load) {
return h(component, props);
}

const me = (this.__P || this._parentDom).lastChild;
const me = dom;

return (
me &&
Expand Down