Skip to content

3rd party packages can cause console.log() to trigger change detection #28647

@ibedard16

Description

@ibedard16

🐞 bug report

Affected Package

The issue is caused by package @angular/core.

Is this a regression?

No.

Description

If a 3rd party library adds behavior to the console.log() function, zone.js will erroneously trigger change detection. If the console.log() statement is in a function bound to the view model, change detection can recursively run.

An easy way to prevent the problem would be to wrap the console.log statement to run outside of angular. However, this is very unwieldy and not-obvious to a developer adding console.log statements to debug their program (aka me).

I recognize that this likely could be considered an issue with the 3rd party package. However, I'm not entirely certain that there is anything that can be done from that package, as it is meant to be a generic package used in a variety of projects, and not just Angular projects.

The 3rd party package, in this case, is Sentry, which overwrites the console.log function in order to record breadcrumbs for error logging. I'm opening an issue both here and against Sentry's repo, because I'm very uncertain which project can/should ultimately fix this issue.

Edit: getsentry/sentry-javascript#1883

🔬 Minimal Reproduction

Reproduction repo that uses Sentry to reproduce the problem: https://github.com/ibedard16/sentry-recursion-demo

Instructions to reproduce are in the readme.

🌍 Your Environment

Angular Version:


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.3.1
Node: 8.11.3
OS: win32 x64
Angular: 7.2.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.1.4
@angular-devkit/schematics        7.3.1
@angular/cli                      7.3.1
@ngtools/webpack                  7.1.4
@schematics/angular               7.3.1
@schematics/update                0.13.1
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.23.1

Anything else relevant?
Using @sentry/browser @4.5.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtime

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions