Skip to content

Commit

Permalink
fix(compiler): default asyncLoading build conditional to true
Browse files Browse the repository at this point in the history
Fixes: #3580

STENCIL-565
  • Loading branch information
tanner-reits committed Aug 13, 2024
1 parent e9acd8c commit 386eb14
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const BUILD: BuildConditionals = {
devTools: false,
shadowDelegatesFocus: true,
initializeNextTick: false,
asyncLoading: false,
asyncLoading: true,
asyncQueue: false,
transformTagName: false,
attachStyles: true,
Expand Down
18 changes: 18 additions & 0 deletions test/wdio/custom-elements-hierarchy-lifecycle/cmp-child.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, h } from '@stencil/core';

import { createAndAppendElement } from './cmp-util.js';

@Component({
tag: 'custom-elements-hierarchy-lifecycle-child',
shadow: true,
})
export class CustomElementsHierarchyLifecycleChild {
async componentDidLoad(): Promise<void> {
createAndAppendElement('DID LOAD CHILD');
return Promise.resolve();
}

render() {
return <p>CHILD CONTENT</p>;
}
}
18 changes: 18 additions & 0 deletions test/wdio/custom-elements-hierarchy-lifecycle/cmp-parent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, h } from '@stencil/core';

import { createAndAppendElement } from './cmp-util.js';

@Component({
tag: 'custom-elements-hierarchy-lifecycle-parent',
shadow: true,
})
export class CustomElementsHierarchyLifecycleParent {
async componentDidLoad(): Promise<void> {
createAndAppendElement('DID LOAD PARENT');
return Promise.resolve();
}

render() {
return <custom-elements-hierarchy-lifecycle-child></custom-elements-hierarchy-lifecycle-child>;
}
}
6 changes: 6 additions & 0 deletions test/wdio/custom-elements-hierarchy-lifecycle/cmp-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const createAndAppendElement = (text: string) => {
const p = document.createElement('p');
p.textContent = text;

document.body.appendChild(p);
};
35 changes: 35 additions & 0 deletions test/wdio/custom-elements-hierarchy-lifecycle/cmp.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Fragment, h } from '@stencil/core';
import { render } from '@wdio/browser-runner/stencil';

import { defineCustomElement as defineCustomElementChildCmp } from '../test-components/custom-elements-hierarchy-lifecycle-child.js';
import { defineCustomElement as defineCustomElementParentCmp } from '../test-components/custom-elements-hierarchy-lifecycle-parent.js';

describe('custom-elements-hierarchy-lifecycle', () => {
before(() => {
defineCustomElementChildCmp();
defineCustomElementParentCmp();
});

it('should call componentDidLoad in the child before the parent', async () => {
expect(customElements.get('custom-elements-hierarchy-lifecycle-child')).toBeDefined();
expect(customElements.get('custom-elements-hierarchy-lifecycle-parent')).toBeDefined();

render({
template: () => (
<>
<custom-elements-hierarchy-lifecycle-parent></custom-elements-hierarchy-lifecycle-parent>
</>
),
});

const elm = document.querySelector('custom-elements-hierarchy-lifecycle-parent');
expect(elm.shadowRoot).toBeDefined();

await browser.waitUntil(() => Boolean(elm.shadowRoot.querySelector('custom-elements-hierarchy-lifecycle-child')));

expect(Array.from(document.querySelectorAll('p')).map((r) => r.textContent)).toEqual([
'DID LOAD CHILD',
'DID LOAD PARENT',
]);
});
});

0 comments on commit 386eb14

Please sign in to comment.