JavaScript Playground: Start debugging runs lesson code after switching to sandbox #133

Closed
opened 2026-05-13 12:17:12 +00:00 by spikerj · 1 comment
Owner

Summary

When switching from Lessons mode to Sandbox mode and using Start debugging, the debugger executes code from the previous Lessons session instead of the code shown in the Sandbox editor.

Steps to reproduce

  1. Open the JavaScript Playground in Lessons mode with lesson code (e.g. console.log("Hello from JavaScript!");).
  2. Switch to Sandbox mode.
  3. Enter different sandbox code in the editor (e.g. var testing = 'hello';).
  4. Use Start debugging.
  5. Observe that output/execution reflects the lesson code (e.g. "Hello from JavaScript!") rather than the sandbox content.

Expected behavior

Start debugging should always run and debug the code that is currently active in the Sandbox editor after mode switch.

Actual behavior

Debugging appears to use a stale reference to Lessons mode code while the UI still shows the Sandbox editor contents.

Notes

Likely causes to investigate: shared state not cleared on mode switch, wrong buffer/source passed to the debugger runner, or the debugger binding to the lesson document instead of the sandbox document.

## Summary When switching from **Lessons** mode to **Sandbox** mode and using **Start debugging**, the debugger executes code from the **previous Lessons** session instead of the code shown in the Sandbox editor. ## Steps to reproduce 1. Open the JavaScript Playground in **Lessons** mode with lesson code (e.g. `console.log("Hello from JavaScript!");`). 2. Switch to **Sandbox** mode. 3. Enter different sandbox code in the editor (e.g. `var testing = 'hello';`). 4. Use **Start debugging**. 5. Observe that output/execution reflects the **lesson** code (e.g. `"Hello from JavaScript!"`) rather than the sandbox content. ## Expected behavior **Start debugging** should always run and debug the code that is currently active in the **Sandbox** editor after mode switch. ## Actual behavior Debugging appears to use a stale reference to **Lessons** mode code while the UI still shows the Sandbox editor contents. ## Notes Likely causes to investigate: shared state not cleared on mode switch, wrong buffer/source passed to the debugger runner, or the debugger binding to the lesson document instead of the sandbox document.
Author
Owner

Root cause confirmed (matches the "wrong buffer/source passed to the debugger" hypothesis in the notes): the step-debugger's source provider read LanguageRunner.code (codeSignal). In advanced sandbox mode the editor binds to the active file (activeFileContent), not codeSignal, so codeSignal still held the prior lesson/beginner code — the debugger ran that stale source while the editor showed the sandbox content.

Fixed in spikersoft-angular PR #51 by pointing the provider at the mode-aware getSourceForChrome() (active file in advanced sandbox, codeSignal otherwise) — the same source the Run Code button already uses, so Run and Debug now execute identical, current editor content. Tests: 29/29 across the JS runner + step-debugger suites. Will close once PR #51 merges.

Root cause confirmed (matches the "wrong buffer/source passed to the debugger" hypothesis in the notes): the step-debugger's source provider read `LanguageRunner.code` (`codeSignal`). In advanced sandbox mode the editor binds to the active file (`activeFileContent`), not `codeSignal`, so `codeSignal` still held the prior lesson/beginner code — the debugger ran that stale source while the editor showed the sandbox content. Fixed in `spikersoft-angular` PR #51 by pointing the provider at the mode-aware `getSourceForChrome()` (active file in advanced sandbox, `codeSignal` otherwise) — the same source the Run Code button already uses, so Run and Debug now execute identical, current editor content. Tests: 29/29 across the JS runner + step-debugger suites. Will close once PR #51 merges.
Sign in to join this conversation.