Skip to content

Commit fd0143b

Browse files
justusromijnadamdbradley
authored andcommitted
fix(runtime): do regular clone of normal slotting (#2694)
Co-Authored-By: Justus Romijn <[email protected]>
1 parent d00ddeb commit fd0143b

File tree

7 files changed

+416
-1
lines changed

7 files changed

+416
-1
lines changed

src/runtime/dom-extras.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ export const patchCloneNode = (HostElementPrototype: any) => {
1313
const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false) as Node;
1414
if (BUILD.slot && !isShadowDom && deep) {
1515
let i = 0;
16-
let slotted;
16+
let slotted, nonStencilNode;
17+
let stencilPrivates = ['s-id', 's-cr', 's-lr', 's-rc', 's-sc', 's-p', 's-cn', 's-sr', 's-sn', 's-hn', 's-ol', 's-nr', 's-si'];
18+
1719
for (; i < srcNode.childNodes.length; i++) {
1820
slotted = (srcNode.childNodes[i] as any)['s-nr'];
21+
nonStencilNode = stencilPrivates.every((privateField) => !(srcNode.childNodes[i] as any)[privateField]);
1922
if (slotted) {
2023
if (BUILD.appendChildSlotFix && (clonedNode as any).__appendChild) {
2124
(clonedNode as any).__appendChild(slotted.cloneNode(true));
2225
} else {
2326
clonedNode.appendChild(slotted.cloneNode(true));
2427
}
2528
}
29+
if (nonStencilNode){
30+
clonedNode.appendChild((srcNode.childNodes[i] as any).cloneNode(true));
31+
}
2632
}
2733
}
2834
return clonedNode;

test/karma/karma.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = function (config) {
9696
// 'test-app/prerender-test/karma.spec.ts',
9797
'test-app/**/*.spec.ts',
9898
'test-app/util.ts',
99+
'test-app/assets/angular.min.js',
99100
{ pattern: 'www/**/*', watched: false, included: false, served: true, nocache: true, type: 'module' },
100101
],
101102

test/karma/test-app/assets/angular.min.js

Lines changed: 350 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/karma/test-app/assets/angular.min.js.map

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/karma/test-app/components.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ export namespace Components {
268268
}
269269
interface SlotNestedOrderParent {
270270
}
271+
interface SlotNgIf {
272+
}
271273
interface SlotNoDefault {
272274
}
273275
interface SlotReorder {
@@ -910,6 +912,12 @@ declare global {
910912
prototype: HTMLSlotNestedOrderParentElement;
911913
new (): HTMLSlotNestedOrderParentElement;
912914
};
915+
interface HTMLSlotNgIfElement extends Components.SlotNgIf, HTMLStencilElement {
916+
}
917+
var HTMLSlotNgIfElement: {
918+
prototype: HTMLSlotNgIfElement;
919+
new (): HTMLSlotNgIfElement;
920+
};
913921
interface HTMLSlotNoDefaultElement extends Components.SlotNoDefault, HTMLStencilElement {
914922
}
915923
var HTMLSlotNoDefaultElement: {
@@ -1091,6 +1099,7 @@ declare global {
10911099
"slot-map-order-root": HTMLSlotMapOrderRootElement;
10921100
"slot-nested-order-child": HTMLSlotNestedOrderChildElement;
10931101
"slot-nested-order-parent": HTMLSlotNestedOrderParentElement;
1102+
"slot-ng-if": HTMLSlotNgIfElement;
10941103
"slot-no-default": HTMLSlotNoDefaultElement;
10951104
"slot-reorder": HTMLSlotReorderElement;
10961105
"slot-reorder-root": HTMLSlotReorderRootElement;
@@ -1372,6 +1381,8 @@ declare namespace LocalJSX {
13721381
}
13731382
interface SlotNestedOrderParent {
13741383
}
1384+
interface SlotNgIf {
1385+
}
13751386
interface SlotNoDefault {
13761387
}
13771388
interface SlotReorder {
@@ -1503,6 +1514,7 @@ declare namespace LocalJSX {
15031514
"slot-map-order-root": SlotMapOrderRoot;
15041515
"slot-nested-order-child": SlotNestedOrderChild;
15051516
"slot-nested-order-parent": SlotNestedOrderParent;
1517+
"slot-ng-if": SlotNgIf;
15061518
"slot-no-default": SlotNoDefault;
15071519
"slot-reorder": SlotReorder;
15081520
"slot-reorder-root": SlotReorderRoot;
@@ -1624,6 +1636,7 @@ declare module "@stencil/core" {
16241636
"slot-map-order-root": LocalJSX.SlotMapOrderRoot & JSXBase.HTMLAttributes<HTMLSlotMapOrderRootElement>;
16251637
"slot-nested-order-child": LocalJSX.SlotNestedOrderChild & JSXBase.HTMLAttributes<HTMLSlotNestedOrderChildElement>;
16261638
"slot-nested-order-parent": LocalJSX.SlotNestedOrderParent & JSXBase.HTMLAttributes<HTMLSlotNestedOrderParentElement>;
1639+
"slot-ng-if": LocalJSX.SlotNgIf & JSXBase.HTMLAttributes<HTMLSlotNgIfElement>;
16271640
"slot-no-default": LocalJSX.SlotNoDefault & JSXBase.HTMLAttributes<HTMLSlotNoDefaultElement>;
16281641
"slot-reorder": LocalJSX.SlotReorder & JSXBase.HTMLAttributes<HTMLSlotReorderElement>;
16291642
"slot-reorder-root": LocalJSX.SlotReorderRoot & JSXBase.HTMLAttributes<HTMLSlotReorderRootElement>;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, h, Host } from "@stencil/core";
2+
3+
@Component({
4+
tag: "slot-ng-if",
5+
shadow: false,
6+
})
7+
export class AngularSlotBinding {
8+
render() {
9+
return (
10+
<Host>
11+
<slot />
12+
</Host>
13+
);
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf8">
3+
<script src="/assets/angular.min.js"></script>
4+
<script src="/build/testapp.esm.js" type="module"></script>
5+
<script src="/build/testapp.js" nomodule></script>
6+
<section id="demo">bla
7+
<section ng-controller="homeCtrl as vm">
8+
<div ng-if="vm.show">
9+
<slot-ng-if><span>{{vm.label}}</span></slot-ng-if>
10+
</div>
11+
</section>
12+
</section>
13+
<script>
14+
angular.module('demo', []).controller('homeCtrl', homeCtrl);
15+
function homeCtrl() {
16+
var vm = this;
17+
vm.label = 'Angular Bound Label';
18+
vm.show = true;
19+
}
20+
angular.bootstrap(document.querySelector('#demo'), ['demo']);
21+
22+
</script>

0 commit comments

Comments
 (0)