File tree Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
19
19
* ` LitElement.renderRoot ` is now ` public readonly ` instead of ` protected ` .
20
20
21
21
### Fixed
22
+ * Initial update is scheduled at construction time rather than connected time ([ #594 ] ( https://github.com/Polymer/lit-element/issues/594 ) ).
22
23
* A reflecting property set immediately after a corresponding attribute
23
24
now reflects properly ([ #592 ] ( https://github.com/Polymer/lit-element/issues/592 ) ).
24
25
* Properties annotated with the ` @query ` and ` @queryAll ` decorators will now
Original file line number Diff line number Diff line change @@ -441,6 +441,8 @@ export abstract class UpdatingElement extends HTMLElement {
441
441
*/
442
442
protected initialize ( ) {
443
443
this . _saveInstanceProperties ( ) ;
444
+ // ensures first update will be caught by an early access of `updateComplete`
445
+ this . requestUpdate ( ) ;
444
446
}
445
447
446
448
/**
@@ -484,15 +486,13 @@ export abstract class UpdatingElement extends HTMLElement {
484
486
485
487
connectedCallback ( ) {
486
488
this . _updateState = this . _updateState | STATE_HAS_CONNECTED ;
487
- // Ensure connection triggers an update. Updates cannot complete before
489
+ // Ensure first connection completes an update. Updates cannot complete before
488
490
// connection and if one is pending connection the `_hasConnectionResolver`
489
491
// will exist. If so, resolve it to complete the update, otherwise
490
492
// requestUpdate.
491
493
if ( this . _hasConnectedResolver ) {
492
494
this . _hasConnectedResolver ( ) ;
493
495
this . _hasConnectedResolver = undefined ;
494
- } else {
495
- this . requestUpdate ( ) ;
496
496
}
497
497
}
498
498
Original file line number Diff line number Diff line change @@ -2202,11 +2202,6 @@ suite('UpdatingElement', () => {
2202
2202
2203
2203
@property ( ) foo = 5 ;
2204
2204
2205
- constructor ( ) {
2206
- super ( ) ;
2207
- this . requestUpdate ( ) ;
2208
- }
2209
-
2210
2205
updated ( _changedProperties : Map < PropertyKey , unknown > ) {
2211
2206
this . updatedCalledCount ++ ;
2212
2207
}
@@ -2220,6 +2215,28 @@ suite('UpdatingElement', () => {
2220
2215
assert . equal ( a . updatedCalledCount , 1 ) ;
2221
2216
} ) ;
2222
2217
2218
+ test ( 'early access of updateComplete waits until first update' , async ( ) => {
2219
+ class A extends UpdatingElement {
2220
+ didUpdate = false ;
2221
+
2222
+ updated ( _changedProperties : Map < PropertyKey , unknown > ) {
2223
+ this . didUpdate = true ;
2224
+ }
2225
+ }
2226
+ customElements . define ( generateElementName ( ) , A ) ;
2227
+ const a = new A ( ) ;
2228
+ let updated = false ;
2229
+ a . updateComplete . then ( ( ) => {
2230
+ updated = true ;
2231
+ assert . isTrue ( a . didUpdate ) ;
2232
+ } ) ;
2233
+ await new Promise ( ( r ) => setTimeout ( r , 20 ) ) ;
2234
+ assert . isFalse ( updated ) ;
2235
+ container . appendChild ( a ) ;
2236
+ await a . updateComplete ;
2237
+ assert . isTrue ( updated ) ;
2238
+ } ) ;
2239
+
2223
2240
test ( 'property reflects after setting attribute in same update cycle' , async ( ) => {
2224
2241
class A extends UpdatingElement {
2225
2242
You can’t perform that action at this time.
0 commit comments