Skip to content

Commit abc8efc

Browse files
bajrangCoderclaude
andauthored
fix(console): restore isolated worker execution by default (#7)
Restore upstream behaviour from Acode-Foundation/Acode#2808, which was reverted as part of the iOS terminal work. The console runs in the isolated worker by default, page execution is opt-in and labelled "Page (unsafe)", and the standalone menu console always uses the worker. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a99a7bb commit abc8efc

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

‎src/lib/console.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ConsoleExecutor, {
88
applyConsoleViewport,
99
executeConsoleCommand,
1010
executeConsoleScript,
11+
resolveConsoleExecutionContext,
1112
} from "./consoleRuntime";
1213

1314
(function () {
@@ -69,14 +70,14 @@ import ConsoleExecutor, {
6970
title: "Choose isolated Worker execution or live page access",
7071
},
7172
children: [
72-
tag("option", {
73-
textContent: "Page",
74-
attr: { value: "page" },
75-
}),
7673
tag("option", {
7774
textContent: "Worker",
7875
attr: { value: "worker" },
7976
}),
77+
tag("option", {
78+
textContent: "Page (unsafe)",
79+
attr: { value: "page" },
80+
}),
8081
],
8182
onchange() {
8283
if (this.value !== "page") return;
@@ -97,7 +98,10 @@ import ConsoleExecutor, {
9798
children: [
9899
$input,
99100
tag("c-input-actions", {
100-
children: [$executionContext, $stopExecution],
101+
children: [
102+
...(isStandaloneConsole ? [] : [$executionContext]),
103+
$stopExecution,
104+
],
101105
}),
102106
],
103107
});
@@ -209,7 +213,7 @@ import ConsoleExecutor, {
209213
async function runStartupScript() {
210214
if (!startupScriptUrl) return;
211215

212-
setExecutionState(true, "worker");
216+
setExecutionState(true);
213217
const result = await executeConsoleScript({
214218
scriptUrl: startupScriptUrl,
215219
workerExecutor: executor,
@@ -448,10 +452,10 @@ import ConsoleExecutor, {
448452
$input.focus();
449453
}
450454

451-
function setExecutionState(running, context = $executionContext.value) {
455+
function setExecutionState(running) {
452456
isExecuting = running;
453457
$console.toggleAttribute("running", running);
454-
$stopExecution.hidden = !running || context !== "worker";
458+
$stopExecution.hidden = !running || $executionContext.value !== "worker";
455459
$input.disabled = running;
456460
$executionContext.disabled = running;
457461
}
@@ -861,7 +865,10 @@ import ConsoleExecutor, {
861865

862866
function executeCommand(code) {
863867
return executeConsoleCommand({
864-
context: $executionContext.value,
868+
context: resolveConsoleExecutionContext(
869+
isStandaloneConsole,
870+
$executionContext.value,
871+
),
865872
code,
866873
workerExecutor: executor,
867874
pageExecutor: execute,

‎src/lib/consoleRuntime.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,19 @@ export function applyConsoleViewport(element, windowObject = window) {
164164
element.style.setProperty("--console-viewport-left", `${left}px`);
165165
}
166166

167+
export function resolveConsoleExecutionContext(
168+
isStandaloneConsole,
169+
selectedContext,
170+
) {
171+
return isStandaloneConsole ? "worker" : selectedContext;
172+
}
173+
167174
/**
168175
* Routes a console command to the isolated worker or the live preview page.
169-
* Page execution keeps browser objects inspectable; workers isolate scripts.
176+
* Page execution is deliberately opt-in because it runs on the preview thread.
170177
*/
171178
export function executeConsoleCommand({
172-
context = "page",
179+
context,
173180
code,
174181
workerExecutor,
175182
pageExecutor,

‎tests/unit/consoleExecutionContext.test.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ import { describe, expect, it } from "vitest";
22
import {
33
executeConsoleCommand,
44
executeConsoleScript,
5+
resolveConsoleExecutionContext,
56
} from "lib/consoleRuntime";
67

78
describe("console execution context", () => {
8-
it("uses isolated worker execution when selected", async () => {
9+
it("forces standalone menu consoles to use the worker", () => {
10+
expect(resolveConsoleExecutionContext(true, "page")).toBe("worker");
11+
expect(resolveConsoleExecutionContext(false, "page")).toBe("page");
12+
});
13+
14+
it("uses isolated worker execution by default", async () => {
915
const calls = [];
1016
const result = await executeConsoleCommand({
1117
context: "worker",
@@ -25,9 +31,10 @@ describe("console execution context", () => {
2531
expect(result.value).toBe("isolated");
2632
});
2733

28-
it("evaluates interactive commands in the live page by default", async () => {
34+
it("restores live page execution when explicitly selected", async () => {
2935
const calls = [];
3036
const result = await executeConsoleCommand({
37+
context: "page",
3138
code: 'document.querySelector("main")',
3239
workerExecutor: {
3340
execute(code) {

0 commit comments

Comments
 (0)