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.
Repro
In a Sandpack preview, run:
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 onconsole-feed'sHook(...), which defers parsing withsetTimeout(...). 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.