fix: Don't run the query string actions until after initialization (#1579)

This commit is contained in:
Dermot Duffy
2024-09-24 17:56:43 -07:00
committed by GitHub
parent 1e0a990855
commit 06345ca01d
7 changed files with 84 additions and 126 deletions
+13 -7
View File
@@ -2,9 +2,9 @@ import { LitElement, ReactiveControllerHost } from 'lit';
import { ActionEventTarget } from '../action-handler-directive';
import { setOrRemoveAttribute } from '../utils/basic';
import { isCardInPanel } from '../utils/ha';
import { ActionExecutionRequestEventTarget } from './actions/utils/execution-request';
import { InitializationAspect } from './initialization-manager';
import { CardElementAPI } from './types';
import { ActionExecutionRequestEventTarget } from './actions/utils/execution-request';
export type ScrollCallback = () => void;
export type MenuToggleCallback = () => void;
@@ -120,16 +120,19 @@ export class CardElementManager {
// See: https://github.com/home-assistant/frontend/blob/273992c8e9c3062c6e49481b6d7d688a07067232/src/common/navigate.ts#L43
window.addEventListener(
'location-changed',
this._api.getQueryStringManager().executeAll,
this._api.getQueryStringManager().requestExecution,
);
// Listen for history state changes (i.e. user using the browser
// back/forward controls).
window.addEventListener('popstate', this._api.getQueryStringManager().executeAll);
window.addEventListener(
'popstate',
this._api.getQueryStringManager().requestExecution,
);
// Manually call the location change handler as the card will be
// Manually request query string execute as the card will be
// disconnected/reconnected when dashboard 'tab' changes happen within HA.
this._api.getQueryStringManager().executeAll();
this._api.getQueryStringManager().requestExecution();
// Make sure reconnections call the initialization code.
this._element.requestUpdate();
@@ -180,8 +183,11 @@ export class CardElementManager {
window.removeEventListener(
'location-changed',
this._api.getQueryStringManager().executeAll,
this._api.getQueryStringManager().requestExecution,
);
window.removeEventListener(
'popstate',
this._api.getQueryStringManager().requestExecution,
);
window.removeEventListener('popstate', this._api.getQueryStringManager().executeAll);
}
}