Skip to content

Commit 6b1e87c

Browse files
fixes some deprecations and removes unused libraries (#23010)
* fixes some deprecations and removes unused libraries * adds changelog * updates packages
1 parent f7afb79 commit 6b1e87c

File tree

15 files changed

+199
-121
lines changed

15 files changed

+199
-121
lines changed

.changelog/23010.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:improvement
2+
ui: resolved multiple Ember deprecations:
3+
- Removed mutation-after-consumption warnings in Outlet by staging state updates outside the render pass
4+
- Replaced deprecated Route#replaceWith/transitionTo usage with RouterService in affected routes
5+
- Avoided mutating objects produced by {{hash}} (setting-on-hash) by switching to tracked POJOs
6+
```

ui/packages/consul-ui/app/components/outlet/index.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Component from '@glimmer/component';
77
import { tracked } from '@glimmer/tracking';
88
import { action } from '@ember/object';
99
import { inject as service } from '@ember/service';
10+
import { schedule } from '@ember/runloop';
1011

1112
class 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
}

ui/packages/consul-ui/app/components/tooltip/index.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
class="tooltip"
88
...attributes
99
{{tooltip
10-
options=(hash
11-
triggerTarget="parentNode"
12-
)
10+
options=this.tooltipOptions
1311
}}
1412
>
1513
{{yield}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: BUSL-1.1
4+
*/
5+
6+
import Component from '@glimmer/component';
7+
8+
export default class TooltipComponent extends Component {
9+
get tooltipOptions() {
10+
return {
11+
triggerTarget: 'parentNode',
12+
...this.args.options,
13+
};
14+
}
15+
}

ui/packages/consul-ui/app/helpers/href-to.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getOwner } from '@ember/application';
1414
import transitionable from 'consul-ui/utils/routing/transitionable';
1515
import wildcard from 'consul-ui/utils/routing/wildcard';
1616
import { routes } from 'consul-ui/router';
17+
import { scheduleOnce } from '@ember/runloop';
1718

1819
const isWildcard = wildcard(routes);
1920

@@ -65,7 +66,7 @@ export default class HrefToHelper extends Helper {
6566

6667
@action
6768
routeWillChange(transition) {
68-
this.recompute();
69+
scheduleOnce('afterRender', this, 'recompute');
6970
}
7071

7172
willDestroy() {

ui/packages/consul-ui/app/helpers/is-href.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Helper from '@ember/component/helper';
77
import { inject as service } from '@ember/service';
88
import { action } from '@ember/object';
9+
import { scheduleOnce } from '@ember/runloop';
910

1011
export default class IsHrefHelper extends Helper {
1112
@service('router') router;
@@ -26,7 +27,13 @@ export default class IsHrefHelper extends Helper {
2627

2728
@action
2829
routeWillChange(transition) {
29-
this.next = transition.to.name.replace('.index', '');
30+
const nextRoute = transition.to.name.replace('.index', '');
31+
// Defer mutation + recompute without anonymous inline function
32+
scheduleOnce('afterRender', this, this._commitNext, nextRoute);
33+
}
34+
35+
_commitNext(nextRoute) {
36+
this.next = nextRoute;
3037
this.recompute();
3138
}
3239

ui/packages/consul-ui/app/modifiers/tooltip.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default modifier(($element, [content], hash = {}) => {
1616
if (typeof content === 'string' && content.trim() === '') {
1717
return;
1818
}
19-
const options = hash.options || {};
19+
const userOptions = hash.options || {};
20+
const options = { ...userOptions };
2021

2122
let $anchor = $element;
2223

@@ -32,7 +33,7 @@ export default modifier(($element, [content], hash = {}) => {
3233
}
3334
content = $anchor.cloneNode(true);
3435
$el.remove();
35-
hash.options.triggerTarget = undefined;
36+
delete options.triggerTarget;
3637
}
3738
// {{tooltip}} will just use the HTML content
3839
if (typeof content === 'undefined') {
@@ -45,7 +46,7 @@ export default modifier(($element, [content], hash = {}) => {
4546
// amount of time specified by the delay
4647
const delay = options.delay || [];
4748
if (typeof delay[1] !== 'undefined') {
48-
hash.options.onShown = (tooltip) => {
49+
options.onShown = (tooltip) => {
4950
clearInterval(interval);
5051
interval = setTimeout(() => {
5152
tooltip.hide();
@@ -68,7 +69,7 @@ export default modifier(($element, [content], hash = {}) => {
6869
plugins: [typeof options.followCursor !== 'undefined' ? followCursor : undefined].filter(
6970
(item) => Boolean(item)
7071
),
71-
...hash.options,
72+
...options,
7273
});
7374

7475
return () => {

ui/packages/consul-ui/app/modifiers/with-overlay.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import tippy, { followCursor } from 'tippy.js';
1313
* {{tooltip 'Text' options=(hash )}}
1414
*/
1515
export default modifier(($element, [content], hash = {}) => {
16-
const options = hash.options || {};
16+
const userOptions = hash.options || {};
17+
const options = { ...userOptions };
1718

1819
let $anchor = $element;
1920

@@ -29,7 +30,7 @@ export default modifier(($element, [content], hash = {}) => {
2930
}
3031
content = $anchor.cloneNode(true);
3132
$el.remove();
32-
hash.options.triggerTarget = undefined;
33+
delete options.triggerTarget;
3334
}
3435
// {{tooltip}} will just use the HTML content
3536
if (typeof content === 'undefined') {

ui/packages/consul-ui/app/routes/dc/kv/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class IndexRoute extends Route {
1717
const params = this.paramsFor(this.routeName);
1818
const key = params.key || '/';
1919
if (!isFolder(key)) {
20-
return this.replaceWith(this.routeName, key + '/');
20+
return this.router.replaceWith(this.routeName, key + '/');
2121
}
2222
}
2323

ui/packages/consul-ui/app/routes/dc/nodes/show/rtt.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
* SPDX-License-Identifier: BUSL-1.1
44
*/
55
import Route from 'consul-ui/routing/route';
6+
import { inject as service } from '@ember/service';
67

78
export default class DcNodesShowRttRoute extends Route {
9+
@service router;
10+
811
redirect(model) {
912
const distances = model?.tomography?.distances;
1013
if (Array.isArray(distances) && distances.length == 0) {
11-
this.replaceWith('dc.nodes.show');
14+
this.router.replaceWith('dc.nodes.show');
1215
}
1316
}
1417
}

0 commit comments

Comments
 (0)