Skip to content

Commit bfbd683

Browse files
fix(runtime): fix blur handling of non-scoped elements (#6314)
* fix(runtime): fix blur handling of non-scoped elements * progress * prettier * revert unneeded changes * better solution * prettier * more progress * more progress * more progress * fix lint * progress * revert * prettier * apply to all non shadow components * tweak if * make test stable * prettier * update tests * prettier * fix last e2e test * only patch if constructor is given * Revert "only patch if constructor is given" This reverts commit 32e1550. * allow to run in node env
1 parent 56fe6e3 commit bfbd683

File tree

30 files changed

+700
-65
lines changed

30 files changed

+700
-65
lines changed

src/runtime/bootstrap-custom-element.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export const proxyCustomElement = (Cstr: any, compactMeta: d.ComponentRuntimeMet
4545

4646
// TODO(STENCIL-914): this check and `else` block can go away and be replaced by just the `scoped` check
4747
if (BUILD.experimentalSlotFixes) {
48-
if (BUILD.scoped && cmpMeta.$flags$ & CMP_FLAGS.scopedCssEncapsulation) {
49-
// This check is intentionally not combined with the surrounding `experimentalSlotFixes` check
50-
// since, moving forward, we only want to patch the pseudo shadow DOM when the component is scoped
48+
if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) {
5149
patchPseudoShadowDom(Cstr.prototype);
5250
}
5351
} else {

src/runtime/bootstrap-lazy.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ export const bootstrapLazy = (lazyBundles: d.LazyBundlesRuntimeData, options: d.
191191

192192
// TODO(STENCIL-914): this check and `else` block can go away and be replaced by just the `scoped` check
193193
if (BUILD.experimentalSlotFixes) {
194-
// This check is intentionally not combined with the surrounding `experimentalSlotFixes` check
195-
// since, moving forward, we only want to patch the pseudo shadow DOM when the component is scoped
196-
if (BUILD.scoped && cmpMeta.$flags$ & CMP_FLAGS.scopedCssEncapsulation) {
194+
if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) {
197195
patchPseudoShadowDom(HostElement.prototype);
198196
}
199197
} else {

src/runtime/dom-extras.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@ function patchHostOriginalAccessor(
566566
accessorName: (typeof validElementPatches)[number] | (typeof validNodesPatches)[number],
567567
node: Node,
568568
) {
569+
/**
570+
* skip this method if a component was imported from a non-browser environment
571+
*/
572+
if (!globalThis.Node || !globalThis.Element) {
573+
return;
574+
}
575+
569576
let accessor;
570577
if (validElementPatches.includes(accessorName as any)) {
571578
accessor = Object.getOwnPropertyDescriptor(Element.prototype, accessorName);

test/end-to-end/src/dom-api/dom-api.e2e.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,14 @@ describe('dom api e2e tests', () => {
241241
await page.waitForChanges();
242242

243243
expect(elm).toEqualText(`
244-
updated text content
244+
dom apiupdated text content
245245
`);
246246

247247
expect(elm).toEqualHtml(`
248248
<dom-api custom-hydrate-flag="">
249+
<span class="blue green red" data-a="a" data-z="z">
250+
dom api
251+
</span>
249252
updated text content
250253
</dom-api>
251254
`);

test/wdio/computed-properties-prop-decorator/cmp.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Fragment, h } from '@stencil/core';
22
import { render } from '@wdio/browser-runner/stencil';
3+
import { $, expect } from '@wdio/globals';
34

45
describe('computed-properties-prop-decorator', () => {
56
beforeEach(async () => {
67
render({
8+
components: [],
79
template: () => (
810
<>
911
<computed-properties-prop-decorator></computed-properties-prop-decorator>
@@ -22,12 +24,12 @@ describe('computed-properties-prop-decorator', () => {
2224
});
2325

2426
it('correctly sets computed property `@Prop()`s and triggers re-renders', async () => {
25-
await expect($('computed-properties-prop-decorator')).toHaveText('no content');
27+
await expect($('computed-properties-prop-decorator').$('div')).toHaveText('no content');
2628

2729
const button = $('button');
2830
await button.click();
2931

30-
await expect($('computed-properties-prop-decorator')).toHaveText('These are my props');
32+
await expect($('computed-properties-prop-decorator').$('div')).toHaveText('These are my props');
3133
});
3234

3335
it('has the default value reflected to the correct attribute on the host', async () => {

test/wdio/computed-properties-state-decorator/cmp.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Fragment, h } from '@stencil/core';
22
import { render } from '@wdio/browser-runner/stencil';
3+
import { $, expect } from '@wdio/globals';
34

45
describe('computed-properties-state-decorator', () => {
56
beforeEach(async () => {
67
render({
8+
components: [],
79
template: () => (
810
<>
911
<computed-properties-state-decorator></computed-properties-state-decorator>
@@ -18,14 +20,14 @@ describe('computed-properties-state-decorator', () => {
1820
});
1921

2022
it('correctly sets computed property `@State()`s and triggers re-renders', async () => {
21-
const el: HTMLElement = document.querySelector('computed-properties-state-decorator');
22-
await expect($(el)).toHaveText(['Has rendered: false', 'Mode: default'].join('\n'));
23+
const el = $('computed-properties-state-decorator').$('div');
24+
await expect(el).toHaveText(['Has rendered: false', 'Mode: default'].join('\n'));
2325

2426
const button = document.querySelector('button');
2527
expect(button).toBeDefined();
2628

2729
await $(button).click();
2830

29-
await expect($(el)).toHaveText(['Has rendered: true', 'Mode: super'].join('\n'));
31+
await expect(el).toHaveText(['Has rendered: true', 'Mode: super'].join('\n'));
3032
});
3133
});

test/wdio/computed-properties-watch-decorator/cmp.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Fragment, h } from '@stencil/core';
22
import { render } from '@wdio/browser-runner/stencil';
3+
import { $, expect } from '@wdio/globals';
34

45
describe('computed-properties-watch-decorator', () => {
56
beforeEach(async () => {
67
render({
8+
components: [],
79
template: () => (
810
<>
911
<computed-properties-watch-decorator></computed-properties-watch-decorator>
@@ -19,7 +21,7 @@ describe('computed-properties-watch-decorator', () => {
1921
});
2022

2123
it('triggers the watch callback when the associated prop changes', async () => {
22-
const el = document.querySelector('computed-properties-watch-decorator');
24+
const el = $('computed-properties-watch-decorator').$('div');
2325
await expect(el).toHaveText(['First name called with: not yet', 'Last name called with: not yet'].join('\n'));
2426

2527
const button = document.querySelector('button');

test/wdio/dom-reattach/cmp-root.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, h, Host, Prop } from '@stencil/core';
1+
import { Component, h, Prop } from '@stencil/core';
22

33
@Component({
44
tag: 'dom-reattach',
@@ -22,11 +22,11 @@ export class DomReattach {
2222

2323
render() {
2424
return (
25-
<Host>
25+
<div>
2626
<p>componentWillLoad: {this.willLoad}</p>
2727
<p>componentDidLoad: {this.didLoad}</p>
2828
<p>disconnectedCallback: {this.didUnload}</p>
29-
</Host>
29+
</div>
3030
);
3131
}
3232
}

test/wdio/dom-reattach/cmp.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ describe('dom-reattach', function () {
3232
componentDidLoad: 1
3333
disconnectedCallback: ${disconnectCount}`;
3434

35-
await expect($('dom-reattach')).toHaveText(lifecycleTextWithDisconnectCount(0));
35+
const $cmp = $('dom-reattach').$('div');
36+
await expect($cmp).toHaveText(lifecycleTextWithDisconnectCount(0));
3637

3738
await $('button').click();
38-
await expect($('dom-reattach')).not.toExist();
39+
await expect($cmp).not.toExist();
3940

4041
await $('button').click();
41-
await expect($('dom-reattach')).toHaveText(lifecycleTextWithDisconnectCount(1));
42+
await expect($cmp).toHaveText(lifecycleTextWithDisconnectCount(1));
4243

4344
await $('button').click();
44-
await expect($('dom-reattach')).not.toExist();
45+
await expect($cmp).not.toExist();
4546

4647
await $('button').click();
47-
await expect($('dom-reattach')).toHaveText(lifecycleTextWithDisconnectCount(2));
48+
await expect($cmp).toHaveText(lifecycleTextWithDisconnectCount(2));
4849
});
4950
});
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import { h } from '@stencil/core';
22
import { render } from '@wdio/browser-runner/stencil';
3+
import { $, expect } from '@wdio/globals';
34

45
import type { DynamicImport } from './dynamic-import.js';
56

67
describe('tag-names', () => {
78
beforeEach(() => {
89
render({
10+
components: [],
911
template: () => <dynamic-import></dynamic-import>,
1012
});
1113
});
1214

1315
it('should load content from dynamic import', async () => {
14-
await expect($('dynamic-import')).toHaveText('1 hello1 world1');
16+
await expect($('dynamic-import').$('div')).toHaveText('1 hello1 world1');
1517

16-
const dynamicImport = document.querySelector('dynamic-import') as HTMLElement & DynamicImport;
18+
const dynamicImport = document.querySelector('dynamic-import') as unknown as HTMLElement & DynamicImport;
1719
dynamicImport.update();
1820

19-
await expect($('dynamic-import')).toHaveText('2 hello2 world2');
21+
await expect($('dynamic-import').$('div')).toHaveText('2 hello2 world2');
2022
});
2123
});

0 commit comments

Comments
 (0)