8000 Add Warning/Error if computed signals create a loop · Issue #61273 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Add Warning/Error if computed signals create a loop #61273

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

Closed
marcelMaier opened this issue May 12, 2025 · 3 comments
Closed

Add Warning/Error if computed signals create a loop #61273

marcelMaier opened this issue May 12, 2025 · 3 comments
Labels
feature Issue that requests a new feature

Comments

@marcelMaier
Copy link

Is your feature request related to a problem? Please describe.
No I can't find a related issue

🚀 feature request

Description

If I have for example a code like this:

 a = signal("A");
 b = signal("B");

 c = computed(() => {
  console.log("c");
  return this.a() + this.d();
 });

 d = computed(() => {
  console.log("d");
  return this.a() + this.c();
 });

// And a call like this in ngOnInit
  this.a.set("Ax");
  console.log(this.c());
  console.log(this.d());

Angular will show me the following in the developer console of the browser:

Image

I would expect angular to already show an error or warning right in VS Code etc.

Feature Type

I think it's related to both of them but I dont know for sure.

  • [ x ] Angular Language Service VSCode extension
  • [ x ] Angular Language Service server

Describe the solution you'd like

As described above the solution would be to already show an error before in the code editor so a bug like this can't be overseen also it would be useful if angular also wouldn't compile like that cause something has to be wrong if u have a loop inside of ur computed signals.

Describe alternatives you've considered

Have you considered any alternative solutions or workarounds?

Anything else relevant?

@marcelMaier marcelMaier added the feature Issue that requests a new feature label May 12, 2025
@atscott atscott transferred this issue from angular/vscode-ng-language-service May 12, 2025
@pkozlowski-opensource
Copy link
Member

As described above the solution would be to already show an error before in the code editor so a bug like this can't be overseen also it would be useful if angular also wouldn't compile like that cause something has to be wrong if u have a loop inside of ur computed signals.

This is not feasible in general as signal dependency tracking is dynamic and a set of dependencies can change as the application runs - hence the runtime check / error.

@marcelMaier
Copy link
Author

I know there will be cases where it's not possible to detect this but I think there are also cases like this where it is possible.

@alxhub
Copy link
Member
alxhub commented May 12, 2025

As Pawel says, this is just not possible to determine statically in all but the simplest cases.

In your code snippet for example, the compiler cannot know that c or d aren't reassigned in a way that would avoid a cycle.

@alxhub alxhub closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

3 participants
0