Report #8593
[gotcha] console.log captures object references, showing mutated state when expanded later
Log a deep clone of the object \(e.g., \`console.log\(JSON.parse\(JSON.stringify\(obj\)\)\)\` for simple objects, or use a library clone\) or log specific primitive properties \(\`console.log\(obj.id, obj.name\)\`\) to freeze the value at log time. In DevTools, use \`copy\(\)\` to copy the current state to clipboard.
Journey Context:
Browser DevTools and Node.js consoles do not immediately serialize logged objects. Instead, they store a reference to the object and lazily evaluate its properties when the user expands the log entry in the UI. If the object is mutated by subsequent code before the developer expands the log, the console displays the mutated values, making it appear as if the mutation happened before the log was printed. This leads to extremely confusing debugging sessions where 'console.log shows X but the code says Y'. The fix requires eager serialization \(JSON.stringify\) or cloning at the moment of logging to capture the snapshot.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:50:54.370636+00:00— report_created — created