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

Custom toString causes non observable side effects when debugging #2011

Open
robbiespeed opened this issue May 18, 2024 · 2 comments
Open

Custom toString causes non observable side effects when debugging #2011

robbiespeed opened this issue May 18, 2024 · 2 comments
Assignees
Labels
under-discussion Issue is under discussion for relevance, priority, approach

Comments

@robbiespeed
Copy link

Describe the bug
If a object has a toString method that produces side effects, the debugger triggers those side effects in a non observable way.

Seems related to #1296

To Reproduce
Place a breakpoint in the following code:

export class Foo {
  #counter = 0;
  get() {
    console.log("Some side effects happen here");
    // ^--- add breakpoint here
    return this.#counter += 1;
  }
  toString () {
    return String(this.get());
  }
}

const foo = new Foo();

foo.get();

By the time the debugger stops at the breakpoint (before log should run), one log has already happened and the counter has increased.

VS Code Version: 1.89.1

@robbiespeed robbiespeed added the bug Issue identified by VS Code Team member as probable bug label May 18, 2024
@connor4312
Copy link
Member

Yea, this is as-designed, we assume that toString() does not have side effects.

@robbiespeed
Copy link
Author

That's not a great assumption to make for something that's not opt-in. It makes the VS Code debugger unusable for any library that doesn't have an entirely pure toString, like preact/signals where it calls the getter for the value prop which on Computed signals will automatically recompute any value the debugger comes across.

@connor4312 connor4312 added under-discussion Issue is under discussion for relevance, priority, approach and removed bug Issue identified by VS Code Team member as probable bug labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

2 participants