salesforce / akita

🚀 State Management Tailored-Made for JS Applications
https://salesforce.github.io/akita/
Apache License 2.0
3.7k stars 342 forks source link

In new angular v16 i'm getting ERROR TypeError: this.userQuery.select is not a function #1074

Open samiulllah opened 11 months ago

samiulllah commented 11 months ago

Is this a regression?

Yes

Description

After updating angular v11 to v16 the akita is giving error in angular main.js:23 ERROR TypeError: this.userQuery.select is not a function at main.js:1:262487 at u.<computed> (polyfills.js:23:32704) at A.invokeTask (polyfills.js:23:9550) at Object.onInvokeTask (main.js:23:169287) at A.invokeTask (polyfills.js:23:9471) at A.runTask (polyfills.js:23:4559) at A.invokeTask (polyfills.js:23:10688) at A.invoke (polyfills.js:23:10578) at Z.s.args.<computed> (polyfills.js:23:32402) my code chunk that raise this error is, `ngOnInit(): void { if (environment.phone) { document.body.classList.add('phone'); } else { document.body.classList.add('tablet'); }

this.screenOrientationService.lockPhone('portrait');

const userQuerySubscription = this.userQuery .select('accessToken') .pipe( filter((v) => !!v), first() ) .subscribe(() => this.userStore.getDetails());

this.subscriptions.add(userQuerySubscription);`

I suspect that might be angular is consuming the state/store before it's avilable. Anyone else have such issue in new angular version? as it was working fine in old v11 of angular.

Please provide a link to a minimal reproduction of the bug

https://stackoverflow.com/questions/77354907/angular-v16-and-akita-is-giving-error-typeerror-this-userquery-select-is-not-a

Please provide the exception or error you saw

main.js:23 ERROR TypeError: this.userQuery.select is not a function
    at main.js:1:262487
    at u.<computed> (polyfills.js:23:32704)
    at A.invokeTask (polyfills.js:23:9550)
    at Object.onInvokeTask (main.js:23:169287)
    at A.invokeTask (polyfills.js:23:9471)
    at A.runTask (polyfills.js:23:4559)
    at A.invokeTask (polyfills.js:23:10688)
    at A.invoke (polyfills.js:23:10578)
    at Z.s.args.<computed> (polyfills.js:23:32402)

Please provide the environment you discovered this bug in

development

Anything else?

I'm suspecting that angular v16 consume stores/queries before they are avilable resulting in undefined.

Do you want to create a pull request?

No

samiulllah commented 11 months ago

This issue is resolved by me you can read at https://stackoverflow.com/questions/77354907/angular-v16-and-akita-is-giving-error-typeerror-this-userquery-select-is-not-a

hakimio commented 7 months ago

Another solution could be to use getter:

get selectAll$() {
    return this.selectAll();
}