Skip to content

Commit efb40d5

Browse files
johnjenkinsJohn Jenkinschristian-bromann
authored
feat(slot-polyfill): patch insertBefore & slotted node parentNode (#6096)
* chore: init * feat(slot-polyfill): patch `insertBefore` & slotted `parentNode` * chore: more tests --------- Co-authored-by: John Jenkins <john.jenkins@nanoporetech.com> Co-authored-by: Christian Bromann <git@bromann.dev>
1 parent 2503dc5 commit efb40d5

File tree

13 files changed

+446
-52
lines changed

13 files changed

+446
-52
lines changed

src/declarations/stencil-private.ts

+80-2
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ export interface RenderNode extends HostElement {
14041404
['s-sr']?: boolean;
14051405

14061406
/**
1407-
* Slot name
1407+
* Slot name of either the slot itself or the slotted node
14081408
*/
14091409
['s-sn']?: string;
14101410

@@ -1441,7 +1441,7 @@ export interface RenderNode extends HostElement {
14411441
* This is a reference for a original location node
14421442
* back to the node that's been moved around.
14431443
*/
1444-
['s-nr']?: RenderNode;
1444+
['s-nr']?: PatchedSlotNode | RenderNode;
14451445

14461446
/**
14471447
* Original Order:
@@ -1526,6 +1526,13 @@ export interface RenderNode extends HostElement {
15261526
*/
15271527
__appendChild?: <T extends Node>(newChild: T) => T;
15281528

1529+
/**
1530+
* On a `scoped: true` component
1531+
* with `experimentalSlotFixes` flag enabled,
1532+
* gives access to the original `insertBefore` method
1533+
*/
1534+
__insertBefore?: <T extends Node>(node: T, child: Node | null) => T;
1535+
15291536
/**
15301537
* On a `scoped: true` component
15311538
* with `experimentalSlotFixes` flag enabled,
@@ -1534,6 +1541,77 @@ export interface RenderNode extends HostElement {
15341541
__removeChild?: <T extends Node>(child: T) => T;
15351542
}
15361543

1544+
export interface PatchedSlotNode extends Node {
1545+
/**
1546+
* Slot name
1547+
*/
1548+
['s-sn']?: string;
1549+
1550+
/**
1551+
* Original Location Reference:
1552+
* A reference pointing to the comment
1553+
* which represents the original location
1554+
* before it was moved to its slot.
1555+
*/
1556+
['s-ol']?: RenderNode;
1557+
1558+
/**
1559+
* Slot host tag name:
1560+
* This is the tag name of the element where this node
1561+
* has been moved to during slot relocation.
1562+
*
1563+
* This allows us to check if the node has been moved and prevent
1564+
* us from thinking a node _should_ be moved when it may already be in
1565+
* its final destination.
1566+
*
1567+
* This value is set to `undefined` whenever the node is put back into its original location.
1568+
*/
1569+
['s-sh']?: string;
1570+
1571+
/**
1572+
* Is a `slot` node when `shadow: false` (or `scoped: true`).
1573+
*
1574+
* This is a node (either empty text-node or `<slot-fb>` element)
1575+
* that represents where a `<slot>` is located in the original JSX.
1576+
*/
1577+
['s-sr']?: boolean;
1578+
1579+
/**
1580+
* On a `scoped: true` component
1581+
* with `experimentalSlotFixes` flag enabled,
1582+
* returns the actual `parentNode` of the component
1583+
*/
1584+
__parentNode?: RenderNode;
1585+
1586+
/**
1587+
* On a `scoped: true` component
1588+
* with `experimentalSlotFixes` flag enabled,
1589+
* returns the actual `nextSibling` of the component
1590+
*/
1591+
__nextSibling?: RenderNode;
1592+
1593+
/**
1594+
* On a `scoped: true` component
1595+
* with `experimentalSlotFixes` flag enabled,
1596+
* returns the actual `previousSibling` of the component
1597+
*/
1598+
__previousSibling?: RenderNode;
1599+
1600+
/**
1601+
* On a `scoped: true` component
1602+
* with `experimentalSlotFixes` flag enabled,
1603+
* returns the actual `nextElementSibling` of the component
1604+
*/
1605+
__nextElementSibling?: RenderNode;
1606+
1607+
/**
1608+
* On a `scoped: true` component
1609+
* with `experimentalSlotFixes` flag enabled,
1610+
* returns the actual `nextElementSibling` of the component
1611+
*/
1612+
__previousElementSibling?: RenderNode;
1613+
}
1614+
15371615
export type LazyBundlesRuntimeData = LazyBundleRuntimeData[];
15381616

15391617
export type LazyBundleRuntimeData = [

src/mock-doc/node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class MockNode {
182182

183183
remove() {
184184
if (this.parentNode != null) {
185-
this.parentNode.removeChild(this);
185+
(this as any).__parentNode ? (this as any).__parentNode.removeChild(this) : this.parentNode.removeChild(this);
186186
}
187187
}
188188

src/runtime/client-hydrate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { doc, plt } from '@platform';
33
import { CMP_FLAGS } from '@utils';
44

55
import type * as d from '../declarations';
6-
import { patchNextPrev } from './dom-extras';
6+
import { patchSlottedNode } from './dom-extras';
77
import { createTime } from './profile';
88
import {
99
COMMENT_NODE_ID,
@@ -195,7 +195,7 @@ export const initializeClientHydrate = (
195195

196196
if (BUILD.experimentalSlotFixes) {
197197
// patch this node for accessors like `nextSibling` (et al)
198-
patchNextPrev(slottedItem.node);
198+
patchSlottedNode(slottedItem.node);
199199
}
200200
}
201201

0 commit comments

Comments
 (0)