Skip to content

fix(client): capture console values at log time#1295

Open
Sembauke wants to merge 1 commit intocodesandbox:mainfrom
Sembauke:fix/console-log-snapshot
Open

fix(client): capture console values at log time#1295
Sembauke wants to merge 1 commit intocodesandbox:mainfrom
Sembauke:fix/console-log-snapshot

Conversation

@Sembauke
Copy link

Summary

Fixes console payload mutation in Sandpack previews by capturing log data at call time.

When a mutable value is logged and then mutated immediately after, the first log could incorrectly show the later mutated value. This happened because the previous hook path relied on delayed parsing.

This PR updates the inject script to:

  • wrap console methods directly,
  • parse/encode payloads synchronously before mutation can occur,
  • preserve the existing postMessage payload shape.

Tests

Added sandpack-client/src/inject-scripts/consoleHook.test.ts with regressions for:

  • mutable array snapshot behavior,
  • unchanged primitive payload behavior.

Verification

  • corepack yarn workspace @codesandbox/sandpack-client test src/inject-scripts/consoleHook.test.ts
  • corepack yarn workspace @codesandbox/sandpack-client build

Closes #1294

@codesandbox
Copy link

codesandbox bot commented Mar 26, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel
Copy link

vercel bot commented Mar 26, 2026

@Sembauke is attempting to deploy a commit to the CodeSandbox Team on Vercel.

A member of the Team first needs to authorize it.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant