NewsCrawler.org

Deleting a console.log broke production through a lazily initialized getter

During a routine release, a team deleted console.log statements across the project, and CI plus the test environment passed without errors. Twenty minutes after launch, some users saw the price as undefined on the product detail page, but only for products with tiered pricing rules. After a rollback, git diff showed 47 changed files, 38 of them console.log deletions, and the line that broke the page turned out to be console.log('price config:', product.priceConfig). The product object came from a state-management layer, and its priceConfig is a getter[1] with lazy initialization[2]: the first access parses the raw pricing rules and caches the result. The deleted log, written in a component's setup before the rendering code, was the first and only place that triggered the getter.

The rendering code read the private _priceConfig directly through bracket syntax to bypass TypeScript's access restrictions, and that property stays null until the getter runs. With the log removed, the getter was never triggered, _priceConfig stayed null, and the page showed undefined.

Three side-effect patterns recur in such code: logging a reactive Proxy[3] object in Vue 3 fires the get trap and performs dependency collection; serialization can implicitly call toString or Symbol.toPrimitive and run code that sets state; and the reference console.log holds can keep WeakRef[4]-tracked objects alive and change garbage collection. The team now strips console and debugger at build time with esbuild's drop option, noting that this removes the whole statement together with its side effects. The real fix was in the code design: initialize the config eagerly or through an explicit init method, expose it only through the public getter, throw an error when it is uninitialized, and add ESLint rules that keep getters free of side effects.

Read the original juejin.cn

Discussion

Most commenters blame the code design and the colleague who accessed the private field directly rather than the deleted log, and some say code that works should be left alone. One commenter asks whether AI code review before a commit would have caught the problem.

Sources

  • CNJuejin ZH

    删了一个没用的 console.log,生产环境直接崩了!

    22 likes1,736 views19 comments17 saves

Published: First seen: Читать по-русски

Open as a page