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

fix(polyfill): slot child fix #2375

Merged
merged 1 commit into from
May 5, 2020
Merged
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
33 changes: 17 additions & 16 deletions src/runtime/dom-extras.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as d from '../declarations';
import { BUILD } from '@app-data';
import { CMP_FLAGS } from '@utils';
import { CMP_FLAGS, HOST_FLAGS } from '@utils';
import { PLATFORM_FLAGS } from './runtime-constants';
import { plt, supportsShadow } from '@platform';
import { plt, supportsShadow, getHostRef } from '@platform';

export const patchCloneNode = (HostElementPrototype: any) => {
const orgCloneNode = HostElementPrototype.cloneNode;
Expand Down Expand Up @@ -44,20 +44,17 @@ export const patchSlotAppendChild = (HostElementPrototype: any) => {
};

export const patchChildSlotNodes = (elm: any, cmpMeta: d.ComponentRuntimeMeta) => {
class FakeNodeList extends Array {
item(n: number) {
return this[n];
}
}
if (cmpMeta.$flags$ & CMP_FLAGS.needsShadowDomShim) {
const childrenFn = elm.__lookupGetter__('children');
const childNodesFn = elm.__lookupGetter__('childNodes');

Object.defineProperty(elm, 'children', {
get() {
const children = childrenFn.call(this);
if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) {
const slotNode = getHostSlotNode(children, '');
if (slotNode && slotNode.parentNode) {
return slotNode.parentNode.children;
}
}
return children;
return this.childNodes.map((n: any) => n.nodeType === 1);
},
});

Expand All @@ -70,13 +67,17 @@ export const patchChildSlotNodes = (elm: any, cmpMeta: d.ComponentRuntimeMeta) =
Object.defineProperty(elm, 'childNodes', {
get() {
const childNodes = childNodesFn.call(this);
if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) {
const slotNode = getHostSlotNode(childNodes, '');
if (slotNode && slotNode.parentNode) {
return slotNode.parentNode.childNodes;
if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0 && getHostRef(this).$flags$ & HOST_FLAGS.hasRendered) {
const result = new FakeNodeList();
for (let i = 0; i < childNodes.length; i++) {
const slot = childNodes[i]['s-nr'];
if (slot) {
result.push(slot);
}
}
return result
}
return childNodes;
return FakeNodeList.from(childNodes);
},
});
}
Expand Down