Skip to content

Console logs can show mutated values instead of call-time snapshots #1294

@Sembauke

Description

@Sembauke

Repro

In a Sandpack preview, run:

const numbers = [1, 2, 3];
console.log(numbers);
numbers.push(4);
console.log(numbers);

Current behavior

The first log can show the mutated value (for example [1,2,3,4]) instead of the original snapshot ([1,2,3]).

Expected behavior

Each console message should reflect the value at the moment console.log(...) was called.

Root cause

@codesandbox/sandpack-client's inject script currently relies on console-feed's Hook(...), which defers parsing with setTimeout(...). That delayed parse reads references after mutation, so the first message can be stale/incorrect.

Suggested direction

Capture/parse/encode the console arguments synchronously in the injected console wrapper before later mutations happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions