-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lifecycles): defer connectedCallback processing until all compone…
…nts are registered (#1930)
- Loading branch information
1 parent
f5817a0
commit 0f302eb
Showing
8 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Component, h } from "@stencil/core"; | ||
import output from "./output"; | ||
|
||
@Component({ | ||
tag: "cmp-a", | ||
shadow: true | ||
}) | ||
export class Cmpa { | ||
async componentWillLoad() { | ||
output("componentWillLoad-a"); | ||
} | ||
|
||
async componentDidLoad() { | ||
output("componentDidLoad-a"); | ||
} | ||
|
||
render() { | ||
return <slot />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {Component, h } from "@stencil/core"; | ||
import output from "./output"; | ||
|
||
@Component({ | ||
tag: "cmp-b", | ||
shadow: true | ||
}) | ||
export class Cmpb { | ||
async componentWillLoad() { | ||
output("componentWillLoad-b"); | ||
} | ||
|
||
async componentDidLoad() { | ||
output("componentDidLoad-b"); | ||
} | ||
|
||
render() { | ||
return <slot />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Host, Component, h } from "@stencil/core"; | ||
import output from "./output"; | ||
|
||
@Component({ | ||
tag: "cmp-c", | ||
shadow: true | ||
}) | ||
export class Cmpc { | ||
async componentWillLoad() { | ||
output("componentWillLoad-c"); | ||
} | ||
|
||
componentDidLoad() { | ||
output("componentDidLoad-c"); | ||
} | ||
|
||
render() { | ||
return( <Host><div>hello</div></Host>); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf8" /> | ||
<script src="/build/testapp.esm.js" type="module"></script> | ||
<script src="/build/testapp.js" nomodule></script> | ||
|
||
<!-- Component are nested in reverse alphabetical order --> | ||
|
||
<cmp-c> | ||
<cmp-b> | ||
<cmp-a></cmp-a> | ||
</cmp-b> | ||
</cmp-c> | ||
|
||
<ol id="lifecycle-loads" class="lifecycle-loads"></ol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { setupDomTests } from '../util'; | ||
|
||
|
||
describe('lifecycle-nested', function() { | ||
const { setupDom, tearDownDom } = setupDomTests(document); | ||
let app: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
app = await setupDom('/lifecycle-nested/index.html'); | ||
}); | ||
afterEach(tearDownDom); | ||
|
||
it('fire load methods in order for nested elements', async () => { | ||
let loads = app.querySelectorAll('.lifecycle-loads li'); | ||
expect(loads.length).toBe(6); | ||
expect(loads[0].textContent).toBe('componentWillLoad-c'); | ||
expect(loads[1].textContent).toBe('componentWillLoad-b'); | ||
expect(loads[2].textContent).toBe('componentWillLoad-a'); | ||
expect(loads[3].textContent).toBe('componentDidLoad-a'); | ||
expect(loads[4].textContent).toBe('componentDidLoad-b'); | ||
expect(loads[5].textContent).toBe('componentDidLoad-c'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default function(msg: string, id = "lifecycle-loads") { | ||
const listEntry = document.createElement("li"); | ||
listEntry.innerText = msg; | ||
document.getElementById(id)!.appendChild(listEntry); | ||
} |