@@ -7,6 +7,7 @@ import Component from '@glimmer/component';
77import { tracked } from '@glimmer/tracking' ;
88import { action } from '@ember/object' ;
99import { inject as service } from '@ember/service' ;
10+ import { schedule } from '@ember/runloop' ;
1011
1112class State {
1213 constructor ( name ) {
@@ -23,11 +24,20 @@ export default class Outlet extends Component {
2324
2425 @tracked element ;
2526 @tracked routeName ;
26- @tracked state ;
27- @tracked previousState ;
27+ @tracked _state = new State ( 'idle' ) ;
28+ @tracked _previousState = new State ( 'idle' ) ;
2829 @tracked endTransition ;
30+ // Non-tracked staging variable (won't trigger tracking violations)
31+ _stagingState = null ;
2932
3033 @tracked route ;
34+ get state ( ) {
35+ return this . _stagingState || this . _state ;
36+ }
37+
38+ get previousState ( ) {
39+ return this . _previousState ;
40+ }
3141
3242 get model ( ) {
3343 return this . args . model || { } ;
@@ -81,8 +91,14 @@ export default class Outlet extends Component {
8191 startLoad ( transition ) {
8292 const outlet = this . routlet . findOutlet ( transition . to . name ) || 'application' ;
8393 if ( this . args . name === outlet ) {
84- this . previousState = this . state ;
85- this . state = new State ( 'loading' ) ;
94+ this . _stagingState = new State ( 'loading' ) ;
95+ // Commit after render
96+ schedule ( 'afterRender' , ( ) => {
97+ this . _previousState = this . _state ;
98+
99+ this . _state = this . _stagingState || new State ( 'loading' ) ;
100+ this . _stagingState = null ;
101+ } ) ;
86102 this . endTransition = this . routlet . transition ( ) ;
87103 let duration ;
88104 if ( this . element ) {
@@ -103,9 +119,14 @@ export default class Outlet extends Component {
103119
104120 @action
105121 endLoad ( transition ) {
106- if ( this . state . matches ( 'loading' ) ) {
107- this . previousState = this . state ;
108- this . state = new State ( 'idle' ) ;
122+ const currentState = this . _stagingState || this . _state ;
123+ if ( currentState . matches ( 'loading' ) ) {
124+ this . _stagingState = new State ( 'idle' ) ;
125+ schedule ( 'afterRender' , ( ) => {
126+ this . _previousState = this . _state ;
127+ this . _state = this . _stagingState || new State ( 'idle' ) ;
128+ this . _stagingState = null ;
129+ } ) ;
109130 }
110131 if ( this . args . name === 'application' ) {
111132 this . setAppRoute ( this . router . currentRouteName ) ;
@@ -115,7 +136,6 @@ export default class Outlet extends Component {
115136 @action
116137 connect ( ) {
117138 this . routlet . addOutlet ( this . args . name , this ) ;
118- this . previousState = this . state = new State ( 'idle' ) ;
119139 this . router . on ( 'routeWillChange' , this . startLoad ) ;
120140 this . router . on ( 'routeDidChange' , this . endLoad ) ;
121141 }
0 commit comments