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(shadowDomShim): slot behaviour #2938

Closed
wants to merge 71 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
1344949
feature(scoped / shadow-shim slots): patched most dom accessors / met…
johnjenkins Jun 24, 2021
113d05b
don't hide new, no-home slotted nodes if we're in a spec test.
johnjenkins Jun 24, 2021
1887226
rm jest clearCache
johnjenkins Jun 25, 2021
cf419c4
style(rm added space)
johnjenkins Jun 25, 2021
4e8b9bd
re-add 'shadowRoot' for shimmed components
johnjenkins Jun 25, 2021
2109f0a
Merge branch 'master' into fix-scoped-slot-render
johnjenkins Jun 25, 2021
5f8efe3
Merge branch 'master' into fix-scoped-slot-render
johnjenkins Jun 25, 2021
f9a0063
feat(no-node slot fallback content): removed all <slot-fb> nodes for …
johnjenkins Jun 30, 2021
60caedf
Merge branch 'fix-scoped-slot-render' of github.com:johnjenkins/stenc…
johnjenkins Jun 30, 2021
40cfde4
re-add es5 flag to karma npm start
johnjenkins Jun 30, 2021
7d85c51
fix(slot): patched textContent when using slot polyfill
johnjenkins Jul 1, 2021
e564064
fix(slot): apply slot polyfill patches immediately to fix external in…
johnjenkins Jul 1, 2021
f8e9349
fix(nested slots): non-shadow nesting slots without 'slot-fb' now works
johnjenkins Jul 5, 2021
4e12078
fix(non-shadow slot fallback content): added inline display when hidi…
johnjenkins Jul 5, 2021
12d6c4b
test(deeply nested scoped slot): added spec tests for deeply nested s…
johnjenkins Jul 5, 2021
84becb2
fixes - update 'sfc' (slot fallback content) on patch.
johnjenkins Aug 4, 2021
c438190
chore(format): add prettier
rwaskiewicz Jul 1, 2021
0c639ab
format codebase
johnjenkins Aug 6, 2021
16095c7
fix initial incorrect render order of nested slotted content
johnjenkins Aug 11, 2021
18e2595
run prettier
johnjenkins Aug 11, 2021
8390f3b
feature(scoped / shadow-shim slots): patched most dom accessors / met…
johnjenkins Jun 24, 2021
216356a
don't hide new, no-home slotted nodes if we're in a spec test.
johnjenkins Jun 24, 2021
30bc44c
re-add 'shadowRoot' for shimmed components
johnjenkins Jun 25, 2021
0225d29
feat(no-node slot fallback content): removed all <slot-fb> nodes for …
johnjenkins Jun 30, 2021
74e7340
re-add es5 flag to karma npm start
johnjenkins Jun 30, 2021
ff2e5f2
fix(slot): patched textContent when using slot polyfill
johnjenkins Jul 1, 2021
c74ca63
fix(slot): apply slot polyfill patches immediately to fix external in…
johnjenkins Jul 1, 2021
ce4c994
fix(nested slots): non-shadow nesting slots without 'slot-fb' now works
johnjenkins Jul 5, 2021
d9266d5
fix(non-shadow slot fallback content): added inline display when hidi…
johnjenkins Jul 5, 2021
2b745df
test(deeply nested scoped slot): added spec tests for deeply nested s…
johnjenkins Jul 5, 2021
2920ad8
fixes - update 'sfc' (slot fallback content) on patch.
johnjenkins Aug 4, 2021
f121ba8
chore(format): add prettier
rwaskiewicz Jul 1, 2021
145a8d8
format codebase
johnjenkins Aug 6, 2021
ff23428
fix initial incorrect render order of nested slotted content
johnjenkins Aug 11, 2021
a73e337
run prettier
johnjenkins Aug 11, 2021
59de998
make karma work again
johnjenkins Sep 6, 2021
8745114
Merge branch 'fix-scoped-slot-render-rebase' into fix-scoped-slot-render
johnjenkins Sep 6, 2021
f397a98
rv extra prettier git workflow
johnjenkins Sep 6, 2021
5f28d38
Merge branch 'master' into fix-scoped-slot-render
johnjenkins Sep 7, 2021
f3b0d6c
re-fix nested slot relocation. Properly this time.
johnjenkins Sep 24, 2021
046e104
merge stencil main
Nov 26, 2021
0f61991
run prettier
Nov 26, 2021
c3b573b
Merge branch 'main' into fix-scoped-slot-render
johnjenkins Dec 2, 2021
763dc88
Merge branch 'main' into fix-scoped-slot-render
johnjenkins Dec 7, 2021
c5bee9b
Merge branch 'stencil-main' into fix-scoped-slot-render
Jun 22, 2022
3de8a8d
Merge branch 'stencil-main' into fix-scoped-slot-render
Jun 30, 2022
780130e
combat `strictNullChecks`. Fighting the good fight.
Jun 30, 2022
d411afc
prettier
Jun 30, 2022
2939376
Merge branch 'stencil-main' into fix-scoped-slot-render
Aug 30, 2022
359d9ac
Merge branch 'stencil-main' into fix-scoped-slot-render
Nov 16, 2022
4850526
feat(non-shadow components): shim `removeChild` on non-shadow components
Nov 16, 2022
cd18578
Merge branch 'stencil-main' into fix-scoped-slot-render
Jan 12, 2023
66387b8
fix client hydration bug - 'childNodes' are empty on the component no…
Jan 12, 2023
5c5cfbd
fix(shadowDomShim): fixed client hydration when nesting shadow and no…
Feb 9, 2023
e6adff4
fix infinite loop
Feb 10, 2023
aa3665e
Merge branch 'stencil-main' into fix-scoped-slot-render
Feb 10, 2023
1d4a76b
hydration various fallback slot node fixes
Feb 11, 2023
f7e178b
improved fallback slot initial render on client hydration
Feb 13, 2023
16f91c8
fixup for non-shadow forwarded slots
Feb 15, 2023
394e669
prettier
Feb 15, 2023
b84daf1
fixup test
Feb 15, 2023
80f0b3c
Merge branch 'stencil-main' into fix-scoped-slot-render
Feb 15, 2023
42b714a
fix regression
Feb 19, 2023
4fc8fad
fix for mockdoc
Feb 19, 2023
dd4f807
Better handling for slotted hydrated comment nodes.
Mar 2, 2023
96f54ab
Merge branch 'stencil-main' into fix-scoped-slot-render
Mar 2, 2023
b5cd508
Merge branch 'stencil-main' into fix-scoped-slot-render
johnjenkins May 18, 2023
3781677
linting / prettier / jsdocs / revert slightly heavy handed merging
johnjenkins May 19, 2023
dfbdfa1
stop being a idiot
johnjenkins May 19, 2023
046205d
Merge branch 'stencil-main' into fix-scoped-slot-render
johnjenkins May 19, 2023
a311f36
Merge branch 'main' into fix-scoped-slot-render
JessicaSachs May 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ export const BUILD: BuildConditionals = {
lazyLoad: false,
profile: false,
slotRelocation: true,
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
appendChildSlotFix: false,
cloneNodeFix: false,
hydratedAttribute: false,
hydratedClass: true,
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
safari10: false,
scriptDataOpts: false,
// TODO: Remove code related to deprecated `scopedSlotTextContentFix` field.
scopedSlotTextContentFix: false,
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
shadowDomShim: false,
// TODO: Remove code related to deprecated `slotChildNodesFix` field.
slotChildNodesFix: false,
invisiblePrehydration: true,
propBoolean: true,
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/app-core/app-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ export const updateBuildConditionals = (config: Config, b: BuildConditionals) =>
b.constructableCSS = !b.hotModuleReplacement || !!config._isTesting;
b.asyncLoading = !!(b.asyncLoading || b.lazyLoad || b.taskQueue || b.initializeNextTick);
b.cssAnnotations = true;
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
b.appendChildSlotFix = config.extras.appendChildSlotFix;
// TODO: Remove code related to deprecated `slotChildNodesFix` field.
b.slotChildNodesFix = config.extras.slotChildNodesFix;
b.cloneNodeFix = config.extras.cloneNodeFix;
// TODO(STENCIL-661): Remove code related to the dynamic import shim
b.dynamicImportShim = config.extras.__deprecated__dynamicImportShim;
b.lifecycleDOMEvents = !!(b.isDebug || config._isTesting || config.extras.lifecycleDOMEvents);
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
b.safari10 = config.extras.__deprecated__safari10;
// TODO: Remove code related to deprecated `scopedSlotTextContentFix` field.
b.scopedSlotTextContentFix = !!config.extras.scopedSlotTextContentFix;
b.scriptDataOpts = config.extras.scriptDataOpts;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/config/test/validate-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ describe('validation', () => {

it('should set extras defaults', () => {
const { config } = validateConfig(userConfig, bootstrapConfig);
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
expect(config.extras.appendChildSlotFix).toBe(false);
expect(config.extras.cloneNodeFix).toBe(false);
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
Expand All @@ -397,6 +398,7 @@ describe('validation', () => {
expect(config.extras.scriptDataOpts).toBe(false);
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
expect(config.extras.__deprecated__shadowDomShim).toBe(false);
// TODO: Remove code related to deprecated `slotChildNodesFix` field.
expect(config.extras.slotChildNodesFix).toBe(false);
expect(config.extras.initializeNextTick).toBe(false);
expect(config.extras.tagNameTransform).toBe(false);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/config/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const validateConfig = (
}

validatedConfig.extras = validatedConfig.extras || {};
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
validatedConfig.extras.appendChildSlotFix = !!validatedConfig.extras.appendChildSlotFix;
validatedConfig.extras.cloneNodeFix = !!validatedConfig.extras.cloneNodeFix;
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ const getHydrateBuildConditionals = (config: d.ValidatedConfig, cmps: d.Componen
build.devTools = false;
build.hotModuleReplacement = false;
build.cloneNodeFix = false;
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
build.appendChildSlotFix = false;
// TODO: Remove code related to deprecated `slotChildNodesFix` field.
build.slotChildNodesFix = false;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
build.safari10 = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export const getHydrateBuildConditionals = (cmps: d.ComponentCompilerMeta[]) =>
build.member = true;
build.constructableCSS = false;
build.asyncLoading = true;
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
build.appendChildSlotFix = false;
// TODO: Remove code related to deprecated `slotChildNodesFix` field.
build.slotChildNodesFix = false;
build.asyncLoading = true;
build.cloneNodeFix = false;
build.cssAnnotations = true;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
Expand Down
51 changes: 48 additions & 3 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ export interface BuildConditionals extends Partial<BuildFeatures> {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
cssVarShim?: boolean;
constructableCSS?: boolean;
appendChildSlotFix?: boolean;
slotChildNodesFix?: boolean;
scopedSlotTextContentFix?: boolean;
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
appendChildSlotFix: boolean;
// TODO: Remove code related to deprecated `slotChildNodesFix` field.
slotChildNodesFix: boolean;
// TODO: Remove code related to deprecated `scopedSlotTextContentFix` field.
scopedSlotTextContentFix: boolean;
cloneNodeFix?: boolean;
// TODO(STENCIL-661): Remove code related to the dynamic import shim
dynamicImportShim?: boolean;
Expand Down Expand Up @@ -1267,6 +1270,22 @@ export interface HostElement extends HTMLElement {
disconnectedCallback?: () => void;
host?: Element;
forceUpdate?: () => void;
readonly __childNodes?: NodeListOf<ChildNode>;
readonly __children?: HTMLCollectionOf<Element>;
readonly __childElementCount?: number;
readonly __firstChild?: ChildNode | null;
readonly __lastChild?: ChildNode | null;
__innerHTML?: string;
__innerText?: string;
__textContent?: string;
__insertBefore?: <T extends Node>(node: T, child: Node | null) => T;
__append?: (...nodes: (Node | string)[]) => void;
__prepend?: (...nodes: (Node | string)[]) => void;
__appendChild?: <T extends Node>(newChild: T) => T;
__replaceChildren?: (...nodes: (Node | string)[]) => void;
__insertAdjacentElement?: (position: InsertPosition, insertedElement: Element) => Element | null;
__insertAdjacentHTML?: (where: InsertPosition, html: string) => void;
__insertAdjacentText?: (where: InsertPosition, text: string) => void;

// "s-" prefixed properties should not be property renamed
// and should be common between all versions of stencil
Expand Down Expand Up @@ -1566,6 +1585,26 @@ export interface RenderNode extends HostElement {
*/
['s-sn']?: string;

/**
* Parent slot name
*/
['s-psn']?: string;

/**
* Is a slot fallback node
*/
['s-sf']?: boolean;

/**
* Slot has fallback nodes
*/
['s-hsf']?: boolean;

/**
* Slot fallback node text content
*/
['s-sfc']?: string;

/**
* Host element tag name:
* The tag name of the host element that this
Expand All @@ -1581,6 +1620,12 @@ export interface RenderNode extends HostElement {
*/
['s-ol']?: RenderNode;

/**
* Original Order:
* A number representing the order of a slotted node
*/
['s-oo']?: number;

/**
* Node reference:
* This is a reference for a original location node
Expand Down
9 changes: 9 additions & 0 deletions src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,15 @@ export interface StencilConfig {
}

export interface ConfigExtras {
// TODO: Remove code related to deprecated `appendChildSlotFix` field.
/**
* By default, the slot polyfill does not update `appendChild()` so that it appends
* new child nodes into the correct child slot like how shadow dom works. This is an opt-in
* polyfill for those who need it when using `element.appendChild(node)` and expecting the
* child to be appended in the same location shadow dom would. This is not required for
* IE11 or Edge 18, but can be enabled if the app is using `appendChild()`. Defaults to `false`.
*
* @deprecated This is now automatically applied when components do not use `shadow: true`
*/
appendChildSlotFix?: boolean;

Expand Down Expand Up @@ -338,9 +341,12 @@ export interface ConfigExtras {
*/
scriptDataOpts?: boolean;

// TODO: Remove code related to deprecated `scopedSlotTextContentFix` field.
/**
* Experimental flag to align the behavior of invoking `textContent` on a scoped component to act more like a
* component that uses the shadow DOM. Defaults to `false`
*
* @deprecated - this is now automatically applied when components do not use `shadow: true`
*/
scopedSlotTextContentFix?: boolean;

Expand All @@ -364,11 +370,14 @@ export interface ConfigExtras {
*/
initializeNextTick?: boolean;

// TODO: Remove code related to deprecated `slotChildNodesFix` field.
/**
* For browsers that do not support shadow dom (IE11 and Edge 18 and below), slot is polyfilled
* to simulate the same behavior. However, the host element's `childNodes` and `children`
* getters are not patched to only show the child nodes and elements of the default slot.
* Defaults to `false`.
*
* @deprecated - this is now automatically applied when components do not use `shadow: true`
*/
slotChildNodesFix?: boolean;

Expand Down
17 changes: 15 additions & 2 deletions src/declarations/stencil-public-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ export declare function getRenderingRef(): any;

export interface HTMLStencilElement extends HTMLElement {
componentOnReady(): Promise<this>;
readonly __childNodes?: NodeListOf<Node>;
readonly __children?: HTMLCollectionOf<Element>;
readonly __childElementCount?: number;
__innerHTML?: string;
__innerText?: string;
__textContent?: string;
__append?: (...nodes: (Node | string)[]) => void;
__prepend?: (...nodes: (Node | string)[]) => void;
__appendChild?: <T extends Node>(newChild: T) => T;
__replaceChildren?: (...nodes: (Node | string)[]) => void;
__insertAdjacentElement?: (position: InsertPosition, insertedElement: Element) => Element | null;
__insertAdjacentHTML?: (where: InsertPosition, html: string) => void;
__insertAdjacentText?: (where: InsertPosition, text: string) => void;
}

/**
Expand Down Expand Up @@ -620,9 +633,9 @@ export declare function h(sel: any, data: VNodeData | null, children: VNode): VN
*/
export interface VNode {
$flags$: number;
$tag$: string | number | Function;
$tag$: string | number | Function | null;
$elm$: any;
$text$: string;
$text$: string | null;
$children$: VNode[];
$attrs$?: any;
$name$?: string;
Expand Down
8 changes: 4 additions & 4 deletions src/hydrate/runner/create-window.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { cloneWindow, MockWindow } from '@stencil/core/mock-doc';

const templateWindows = new Map<string, Window>();
const templateWindows = new Map<string, MockWindow>();

export function createWindowFromHtml(templateHtml: string, uniqueId: string) {
let templateWindow = templateWindows.get(uniqueId);
if (templateWindow == null) {
templateWindow = new MockWindow(templateHtml) as any;
templateWindow = new MockWindow(templateHtml);
templateWindows.set(uniqueId, templateWindow);
}

const win = cloneWindow(templateWindow);
return win as any;
const win = cloneWindow(templateWindow as any);
return win;
}
2 changes: 1 addition & 1 deletion src/mock-doc/custom-element-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function createCustomElement(customElements: MockCustomElementRegistry, o

proxyElements.set(host, elm);

return host;
return elm;
}

const proxyElements = new WeakMap();
Expand Down
13 changes: 12 additions & 1 deletion src/runtime/bootstrap-custom-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CMP_FLAGS } from '@utils';
import type * as d from '../declarations';
import { connectedCallback } from './connected-callback';
import { disconnectedCallback } from './disconnected-callback';
import { patchCloneNode, patchPseudoShadowDom } from './dom-extras';
import { computeMode } from './mode';
import { proxyComponent } from './proxy-component';
import { PROXY_FLAGS } from './runtime-constants';
Expand Down Expand Up @@ -36,6 +37,16 @@ export const proxyCustomElement = (Cstr: any, compactMeta: d.ComponentRuntimeMet
cmpMeta.$flags$ |= CMP_FLAGS.needsShadowDomShim;
}

if (
cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation ||
(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation && CMP_FLAGS.needsShadowDomShim)
) {
patchPseudoShadowDom(Cstr.prototype);
if (BUILD.cloneNodeFix) {
patchCloneNode(Cstr.prototype);
}
}

const originalConnectedCallback = Cstr.prototype.connectedCallback;
const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
Object.assign(Cstr.prototype, {
Expand Down Expand Up @@ -79,7 +90,7 @@ export const forceModeUpdate = (elm: d.RenderNode) => {
const mode = computeMode(elm);
const hostRef = getHostRef(elm);

if (hostRef.$modeName$ !== mode) {
if (hostRef && hostRef.$modeName$ !== mode) {
const cmpMeta = hostRef.$cmpMeta$;
const oldScopeId = elm['s-sc'];
const scopeId = getScopeId(cmpMeta, mode);
Expand Down