mirror of
https://github.com/Matysh/houseplan-card
synced 2026-10-02 21:01:21 +00:00
fix(editor): a render no longer restarts a failed runtime load (#757)
The lazy-runtime contract (#353) says a non-terminal failure waits for the next explicit intent and that there are no background retries. But _renderBody calls ensure() on every repaint while a surface waits for the editor or onboarding runtime, and to the loader that call was indistinguishable from an intent. Surfaces the core opens without the runtime - the kiosk size dialog after a 3 s hold, the floor import wizard on an empty plan, a dialog a warm remount revives - therefore turned one failure into a loop: the loader's own state change, the toast and its expiry, every hass tick repainted, started a new cycle and showed a new toast every ~3.5 s. A wall tablet whose old hashed chunks answer 404 after an integration update sat in that loop forever. EditorRuntimeLoader.ensure takes an intent: the render calls it as 'reconcile'. A reconcile starts the first cycle a surface needs, but after a non-terminal failure it returns false without loading until an explicit ensure() - a tab, an opener, _requestMode, "Add space" - has started a new cycle. Explicit calls, the terminal fingerprint failure, ready and an in-flight cycle behave as before, for every loader instance. The card's render lines stay line-neutral. smoke_lazy_editor_chunk gains the three surfaces offline through their real paths (a 3 s touch hold on a kiosk card, an empty plan pushed by the server, General settings revived by a remount): one cycle, one notice and an idle loader over 8 s, then the Plan tab and "Add space" heal. On dev: 4 requests / 3 notices, 6 / 2 and 3 / 2. The loader unit test pins reconcile versus intent; the mutant render-reconcile-restarts-editor-runtime-cycle is guarded by the smoke. Issue: #757 User-Visible: yes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qZfe7YS4rqEMKoVeS3GKd
This commit is contained in:
@@ -68,10 +68,19 @@ class FingerprintMismatchError extends Error {}
|
||||
* keeps returning `false` without importing again. Any other failure (network,
|
||||
* parse) reports via `failed` and returns the loader to `idle`, so the NEXT
|
||||
* explicit user intent starts a fresh cycle. There are no background retries.
|
||||
*
|
||||
* A render that finds a surface waiting for the runtime is not an intent
|
||||
* (#757): `ensure('reconcile')` starts the first cycle such a surface needs,
|
||||
* but after a non-terminal failure it returns `false` without loading until
|
||||
* an explicit `ensure()` has started a new cycle. Otherwise every repaint —
|
||||
* the loader's own state change, the failure toast and its expiry, each
|
||||
* `hass` tick — would start another cycle and another toast.
|
||||
*/
|
||||
export class EditorRuntimeLoader<Runtime> {
|
||||
private _state: EditorRuntimeLoaderState = 'idle';
|
||||
private _inFlight: Promise<boolean> | null = null;
|
||||
/** A non-terminal failure waits for the next explicit intent (#757). */
|
||||
private _awaitingIntent = false;
|
||||
|
||||
public constructor(private readonly options: EditorRuntimeLoaderOptions<Runtime>) {}
|
||||
|
||||
@@ -79,10 +88,14 @@ export class EditorRuntimeLoader<Runtime> {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
public ensure(): Promise<boolean> {
|
||||
/** `intent`: `explicit` — a user action or an opening; `reconcile` — a render
|
||||
* that finds a surface waiting for the runtime. */
|
||||
public ensure(intent: 'explicit' | 'reconcile' = 'explicit'): Promise<boolean> {
|
||||
if (this._state === 'ready') return Promise.resolve(true);
|
||||
if (this._state === 'failed') return Promise.resolve(false);
|
||||
if (this._inFlight) return this._inFlight;
|
||||
if (intent === 'reconcile' && this._awaitingIntent) return Promise.resolve(false);
|
||||
this._awaitingIntent = false;
|
||||
this._setState('loading');
|
||||
this._inFlight = this._loadWithRetry().finally(() => {
|
||||
this._inFlight = null;
|
||||
@@ -110,6 +123,7 @@ export class EditorRuntimeLoader<Runtime> {
|
||||
if (error instanceof FingerprintMismatchError) sawMismatch = true;
|
||||
}
|
||||
}
|
||||
this._awaitingIntent = !sawMismatch;
|
||||
this._setState(sawMismatch ? 'failed' : 'idle');
|
||||
this.options.failed?.(lastError, { terminal: sawMismatch });
|
||||
return false;
|
||||
|
||||
@@ -10613,10 +10613,10 @@ export class HouseplanCard extends LitElement {
|
||||
|| this._markerDialog || this._rulesDialog || this._settingsDialog || this._supportDialog
|
||||
|| this._alignDialog || this._backupExportDialog || this._backupImportDialog
|
||||
|| this._kioskDialog || this._vacFit || this._vacCalConfirm);
|
||||
if (onboardingRuntimeRequested && !this._onboardingRuntime) {
|
||||
void this._ensureOnboardingRuntime();
|
||||
if (onboardingRuntimeRequested && !this._onboardingRuntime) { // a render reconciles; it is not an intent (#757)
|
||||
void this._onboardingRuntimeLoader.ensure('reconcile');
|
||||
}
|
||||
if (editorRuntimeRequested && !this._editorRuntime) void this._ensureEditorRuntime();
|
||||
if (editorRuntimeRequested && !this._editorRuntime) void this._editorRuntimeLoader.ensure('reconcile');
|
||||
const model = this._model;
|
||||
const diagnostics = this._renderLife.diagnostics(
|
||||
this.hass, this._markers, (binding) => this._bindingStatus(binding),
|
||||
|
||||
Reference in New Issue
Block a user