Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Angular 19 changes Subscriptions to RxMethodRef #4661

Closed
1 of 2 tasks
leomayer opened this issue Jan 7, 2025 · 4 comments
Closed
1 of 2 tasks

Upgrade to Angular 19 changes Subscriptions to RxMethodRef #4661

leomayer opened this issue Jan 7, 2025 · 4 comments

Comments

@leomayer
Copy link

leomayer commented Jan 7, 2025

Which @ngrx/* package(s) are the source of the bug?

signals

Minimal reproduction of the bug/regression with instructions

I have defined in my signalStore

withChatStates(),
withMethods((state) => {
   startDelay4NewChatSession: rxMethod<boolean>(
				pipe(
					filter((startDelay) => startDelay),
					delay(5000),
					tap(() => state.ready4NewContext()),
				),

and

export function withChatStates(){
...
	withComputed((state) => {
			return {
				isDelayInit: computed(() => state.sessionState() === 'delayInit'),

and in a component

 lstOfSubscriptions:Subscription = autoSubscriptionsUnsubscribe();

ngOnInit():{
   this.lstOfSubscriptions.add(this.chatStore.startDelay4NewChatSession(this.chatStore.isDelayInit))

Expected behavior

With Angular 18 this code works exactly as expected. I add this to rxMethod to my list and it will unsubcribe automatically.

After upgrading I get the error message:

 [ERROR] TS2345: Argument of type 'RxMethodRef' is not assignable to parameter of type 'TeardownLogic'. [plugin angular-compiler]

[UPDATE]: I've figured out that the Subscription is causing the problem. Therefore just a question remains:

Instead of the automatic unsubscribe should I use now a destroy? Do they have the same effect?

BTW: RxMethodRef is not exported

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

"@ngrx/signals": "^19.0.0"
"@angular/compiler": "^19.0.5",
"@angular/core": "^19.0.5",
Linux

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@leomayer leomayer changed the title Upgrade to Angular 19 fails Upgrade to Angular 19 changes Subscriptions to RxMethodRef Jan 7, 2025
@rainerhahnekamp
Copy link
Contributor

@leomayer it would help us a lot of you can use our provided stackblitz to reproduce it.

@markostanimirovic
Copy link
Member

In v19, rxMethod.unsubscribe is renamed to rxMethod.destroy. Read more in the migration guide: https://ngrx.io/guide/migration/v19#rename-rxmethodunsubscribe-to-rxmethoddestroy

If you move this.chatStore.startDelay4NewChatSession(this.chatStore.isDelayInit) from ngOnInit to constructor or provide injector as the second argument:

class MyComponent implements OnInit {
  readonly injector = inject(Injector);


  ngOnInit() {
    this.chatStore.startDelay4NewChatSession(
      this.chatStore.isDelayInit,
      { injector: this.injector }
    );
  }
}

There is no need to do manual cleanup because automatic cleanup will happen on component destruction.

Read rxMethod docs for more info: https://ngrx.io/guide/signals/rxjs-integration#rxmethod

@leomayer
Copy link
Author

leomayer commented Jan 8, 2025

@markostanimirovic: ahhh... thx... That tiny bit of information I didn't conclude from the 'Manual cleanup' section

https://ngrx.io/guide/signals/rxjs-integration#manual-cleanup

@leomayer leomayer mentioned this issue Jan 8, 2025
2 tasks
@leomayer
Copy link
Author

leomayer commented Jan 8, 2025

@rainerhahnekamp I've missed that the unsubscribe is now a destroy and therefore won't work any longer in the given context. A list of subscriptions could be unsubscribed at once. But anyway this is now clarified _/_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants