Skip to content

fix: react to provider changes in all components #519

Open

Description

@anuragxxd

Why?

#448 (fixed for ecc-client-elixir-cloud-registry-service-create by #502) affects the other client components too. They read provider only in firstUpdated(), or handle its changes only in part. Apps that replace the provider, e.g. with one that adds a refreshed token, keep using the old one. Or they lose their provider, or show data from the old one.

We reproduced this on dev with fake providers, in Chromium, Firefox and WebKit, for three of the components (services, WES runs and run). 7 of 8 tests failed. With the change below, all of them pass, and so do the existing WES tests. The other components share the same code. We read them but haven't run them.

Components Problem on dev
service-registry services and service, DRS objects, TRS tools, TRS filer tool-create Ignore changes of provider. A provider set after the first render (without baseUrl) is never used. A baseUrl change replaces a custom provider.
DRS object, TRS tool, WES run and run-create, DRS filer object-create Removing provider leaves no provider instead of falling back to baseUrl.
WES runs A baseUrl change replaces a custom provider.
All of the above A late answer from a replaced provider overwrites the new provider's data. No component ignores it.

What?

  • Move the provider handling of fix(cloud-registry): react to provider changes #502 into one reusable Lit ReactiveController in @elixir-cloud/design. All client packages depend on that package already, so this needs no new package. The controller:
    • uses provider, else a REST provider for baseUrl (one per URL);
    • checks this before each update, and calls the component's reload when it changes;
    • offers isCurrent(provider), so that requests drop the answers of a replaced provider.
  • Export it, e.g. as @elixir-cloud/design/controllers/*. The build currently bundles components/** only.
  • Use it in all components above, and in ecc-client-elixir-cloud-registry-service-create instead of fix(cloud-registry): react to provider changes #502's own code.
  • Tests for each component:
    • a replaced provider is used;
    • a provider set after the first render is used;
    • a baseUrl change keeps a custom provider;
    • removing the provider falls back to baseUrl;
    • a late answer from a replaced provider is ignored.
Sketch of the controller (from our spike)
import type { ReactiveController, ReactiveControllerHost } from "lit";

export interface ProviderHost<P> extends ReactiveControllerHost {
  provider?: P;
  baseUrl: string;
}

export class ProviderController<P extends object> implements ReactiveController {
  current: P | null = null;

  private rest: { baseUrl: string; provider: P } | null = null;

  constructor(
    private readonly host: ProviderHost<P>,
    private readonly createRest: (baseUrl: string) => P,
    private readonly onChange: (provider: P | null) => void
  ) {
    host.addController(this);
  }

  // before each render, so that it already uses the new provider
  hostUpdate(): void {
    const provider = this.resolve();
    if (provider === this.current) return;
    this.current = provider;
    this.onChange(provider);
  }

  isCurrent(provider: P): boolean {
    return provider === this.current;
  }

  private resolve(): P | null {
    const { provider, baseUrl } = this.host;
    if (!baseUrl) {
      this.rest = null;
    } else if (this.rest?.baseUrl !== baseUrl) {
      this.rest = { baseUrl, provider: this.createRest(baseUrl) };
    }
    return provider ?? this.rest?.provider ?? null;
  }
}

Components then load with const provider = this.providers.current and return early after each await if !this.providers.isCurrent(provider). Comparing providers misses the case where a provider comes back (A → B → A). #502's request counter covers that case, so it may be worth keeping.

Out of scope

  • The TES components (ecc-client-ga4gh-tes-*) have no provider at all: they take baseURL and call API functions directly, so apps can't add a token to their requests. That needs a separate issue.

Acceptance criteria

  • In every client component with a provider property, setting, replacing or removing provider or baseUrl at any time makes all later requests use provider, else a REST provider for baseUrl.
  • provider always takes precedence over baseUrl.
  • Answers from a replaced provider are ignored.
  • Tests cover this for each component.

Activity

  1. added
    priority: medium
    type: bug
    workload: days
    on Oct 31, 2026
  2. added
    status: triage
    and removed on Nov 8, 2026
  3. uniqueg commented on Nov 18, 2026

    @uniqueg
    Member

    One more case for the controller: Sourcery found it on #596 and #597, and it applies to every component that handles provider changes today (at least services and service from #577, and service-types and service-info from #596 and #597).

    A load checks whether its provider is still current by comparing it with the provider the component resolved in its last update. Between setting provider or baseUrl and Lit's next update (one microtask), that resolved provider is still the old one. A load from the old registry that settles in that window still applies its data and emits it; the reload starts right after and replaces it, so apps briefly see data of the old registry.

    Suggested fix in the controller: let isCurrent(provider) resolve the provider from the current provider and baseUrl properties instead of returning provider === this.current. Invalidating pending loads in a property setter instead would leave the component loading forever if the property is changed and changed back before the update.

    Test for each component: replace the provider, settle the old provider's request before the next update (e.g. resolve it synchronously after setting the property), and check that its data is neither shown nor emitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumstatus: triagetype: bugworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions