Skip to content

Commit f4bfa88

Browse files
zoidbergclawdclaude
andcommitted
Fix white screen caused by ELECTRON_RUN_AS_NODE in renderer processes
Setting ELECTRON_RUN_AS_NODE=1 on the main process env caused Electron's renderer processes to start as Node.js instead of rendering the UI, resulting in a blank white screen. Replace with ELISA_USE_NODE_SHIM=1 flag that signals the backend to inject ELECTRON_RUN_AS_NODE=1 only into specific child process envs (agentRunner query calls), never the main process. Bump version to 0.2.7. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4e30cc6 commit f4bfa88

6 files changed

Lines changed: 25 additions & 21 deletions

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elisa-backend",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"private": true,
55
"license": "MIT",
66
"type": "module",

backend/src/services/agentRunner.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ describe('AgentRunner', () => {
185185
expect(result.summary).toBe('No output');
186186
});
187187

188-
it('uses Electron shim when ELECTRON_RUN_AS_NODE is set (no system node)', async () => {
188+
it('uses Electron shim when ELISA_USE_NODE_SHIM is set (no system node)', async () => {
189189
const origPath = process.env.ELISA_RESOURCES_PATH;
190-
const origShim = process.env.ELECTRON_RUN_AS_NODE;
190+
const origShim = process.env.ELISA_USE_NODE_SHIM;
191191
process.env.ELISA_RESOURCES_PATH = '/fake/resources';
192-
process.env.ELECTRON_RUN_AS_NODE = '1';
192+
process.env.ELISA_USE_NODE_SHIM = '1';
193193
try {
194194
mockQuery.mockReturnValue(asyncIterable(makeResultMessage()) as any);
195195

@@ -209,16 +209,16 @@ describe('AgentRunner', () => {
209209
} finally {
210210
if (origPath === undefined) delete process.env.ELISA_RESOURCES_PATH;
211211
else process.env.ELISA_RESOURCES_PATH = origPath;
212-
if (origShim === undefined) delete process.env.ELECTRON_RUN_AS_NODE;
213-
else process.env.ELECTRON_RUN_AS_NODE = origShim;
212+
if (origShim === undefined) delete process.env.ELISA_USE_NODE_SHIM;
213+
else process.env.ELISA_USE_NODE_SHIM = origShim;
214214
}
215215
});
216216

217217
it('uses system node when available (no executable override)', async () => {
218218
const origPath = process.env.ELISA_RESOURCES_PATH;
219-
const origShim = process.env.ELECTRON_RUN_AS_NODE;
219+
const origShim = process.env.ELISA_USE_NODE_SHIM;
220220
process.env.ELISA_RESOURCES_PATH = '/fake/resources';
221-
delete process.env.ELECTRON_RUN_AS_NODE;
221+
delete process.env.ELISA_USE_NODE_SHIM;
222222
try {
223223
mockQuery.mockReturnValue(asyncIterable(makeResultMessage()) as any);
224224

@@ -238,8 +238,8 @@ describe('AgentRunner', () => {
238238
} finally {
239239
if (origPath === undefined) delete process.env.ELISA_RESOURCES_PATH;
240240
else process.env.ELISA_RESOURCES_PATH = origPath;
241-
if (origShim === undefined) delete process.env.ELECTRON_RUN_AS_NODE;
242-
else process.env.ELECTRON_RUN_AS_NODE = origShim;
241+
if (origShim === undefined) delete process.env.ELISA_USE_NODE_SHIM;
242+
else process.env.ELISA_USE_NODE_SHIM = origShim;
243243
}
244244
});
245245

backend/src/services/agentRunner.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,17 @@ export class AgentRunner {
177177
allowedTools?: string[],
178178
): Promise<AgentResult> {
179179
// In Electron production, capture stderr for diagnostics.
180-
// When no system Node.js is available (ELECTRON_RUN_AS_NODE is set by
181-
// electron/main.ts), use the Electron binary itself as the runtime.
182-
// When system node exists, let the SDK use it (preserves npm/npx).
180+
// When no system Node.js is available (ELISA_USE_NODE_SHIM is set by
181+
// electron/main.ts), use the Electron binary with ELECTRON_RUN_AS_NODE=1.
182+
// ELECTRON_RUN_AS_NODE must NOT be set on the main process (breaks renderers);
183+
// it's injected only into child process environments here.
183184
const isElectronProd = !!process.env.ELISA_RESOURCES_PATH;
184-
const useElectronShim = isElectronProd && process.env.ELECTRON_RUN_AS_NODE === '1';
185+
const useNodeShim = isElectronProd && process.env.ELISA_USE_NODE_SHIM === '1';
185186
const stderrChunks: string[] = [];
186187
const electronExecConfig = isElectronProd
187188
? {
188-
...(useElectronShim
189-
? { executable: process.execPath, env: { ...process.env } }
189+
...(useNodeShim
190+
? { executable: process.execPath, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' } }
190191
: {}),
191192
stderr: (data: string) => { stderrChunks.push(data); },
192193
}

electron/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,12 @@ async function startBackend(): Promise<void> {
227227
try { fs.linkSync(process.execPath, shimNodeExe); }
228228
catch { fs.copyFileSync(process.execPath, shimNodeExe); }
229229
process.env.PATH = `${process.env.PATH};${nodeShimDir}`;
230-
// ELECTRON_RUN_AS_NODE makes the Electron binary act as Node.js.
231-
// Only set when using the shim; system node doesn't need it.
232-
process.env.ELECTRON_RUN_AS_NODE = '1';
230+
// Signal the backend that the node shim is active. The backend
231+
// will inject ELECTRON_RUN_AS_NODE=1 into specific child process
232+
// environments (agentRunner, testRunner) rather than setting it
233+
// globally -- setting it globally would break Electron's renderer
234+
// processes (white screen).
235+
process.env.ELISA_USE_NODE_SHIM = '1';
233236
console.log('[main] Using Electron node.exe shim (no system node found)');
234237
} catch (err) {
235238
console.error('[main] Failed to create node.exe shim:', err);

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "frontend",
33
"private": true,
4-
"version": "0.2.6",
4+
"version": "0.2.7",
55
"license": "MIT",
66
"type": "module",
77
"scripts": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elisa",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"private": true,
55
"license": "MIT",
66
"author": "Elisa",

0 commit comments

Comments
 (0)