Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.
This repository was archived by the owner on May 1, 2025. It is now read-only.

Query select fires twice and collects observables #1071

@VolvoTruckExpress

Description

@VolvoTruckExpress

Is this a regression?

Yes

Description

I have a simple query:

@Injectable({ providedIn: 'root' })
export class BufferDataImportQuery extends QueryEntity<BufferDataImportState, IBufferDataImport> {
  document$ = this.select(t => t.document);
  originalDocument$ = this.select(t => t.originalDocument);
  xmlDocument$ = this.select(t => t.xmlDocument);
  documentPartner$ = this.select(t => t.document.partner);
  partnerName$ = this.select(t => t.document.partner.name);
  documentDetails$ = this.select(t => t.document?.details);
    ...
  constructor(protected store: BufferDataImportStore) {
    super(store);
  }
}

and a simple store:

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'buffer-data-import' })
export class BufferDataImportStore extends EntityStore<BufferDataImportState, IBufferDataImport> {
  constructor() {
    super();
  }

  public updateDetail(detailId: number, detail: DocumentDetailUI) {
    this.update({ document: { ...this.getValue().document, details: arrayUpdate(this.getValue().document.details, detailId, { ...detail, detail }) } });
  }
}

and in some component:

export class DocumentImportDetailsListComponent implements OnInit, OnDestroy {
  detailsQuery$ = this.query.documentDetails$;
  document$ = this.query.document$;
  readonly$ = this.query.readonly$;

  constructor(
    private service: BufferDataImportService,
    private query: BufferDataImportQuery,
    ...
    ) {

    this.sub.add(this.detailsQuery$.subscribe({
      next: (details) => {
        console.log("test");
        ...
      }
    }));
  }
  ngOnDestroy(): void {
    this.sub.unsubscribe();
  }

The problem is that in the component, the next callback is triggered twice with the same value. This wouldn't be such a trouble since I could use take(1) . However I noticed that this.detailsQuery(Observable).source.source(Observable).source(BehaviorSubject).observers[] array keeps increasing to the order of thousands.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

"@datorama/akita": "^8.0.0",
"@datorama/akita-ng-effects": "^1.0.6",
"@datorama/akita-ng-entity-service": "^8.0.0",
"rxjs": "^7.8.1",
"tslib": "^2.3.0",
"zone.js": "~0.11.8"

Anything else?

The console is spammed with hundreds of messages:

You need to enable the reset functionality:
reset | @ | datorama-akita.js:1105
-- | -- | --
  | (anonymous) | @ | layout-customizations.service.ts:23
  | __tryOrUnsub | @ | Subscriber.js:183
  | next | @ | Subscriber.js:122
  | _next | @ | Subscriber.js:72
  | next | @ | Subscriber.js:49
  | next | @ | Subject.js:39
  | next | @ | BehaviorSubject.js:30
....

Do you want to create a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions