fix(desktop): load renderer from primary's real URL, not local exposure
In wsl-only mode, serverExposure.backendConfig.httpBaseUrl (127.0.0.1:3773) doesn't match the URL the WSL backend actually listens on (the distro IP, e.g. 172.27.152.141:3773). wslhost localhost forwarding is flaky on some Windows hosts, so loadURL at 127.0.0.1 leaves the renderer black-screened with did-fail-load. Plumb the primary instance's resolved httpBaseUrl through onReady to the window service, store it, and let createMain read it. Falls back to serverExposure when nothing's been reported yet so existing behavior (dev mode, activate path before ready) is unchanged.
This commit is contained in:
1 parent
d71f3b1dc5
commit
1ebb0e5a47
5 files changed
+37
-14
No files matched your search
@@ -176,7 +176,12 @@ export interface BackendInstanceSpec {
|
||||
readonly id: BackendInstanceId;
|
||||
readonly label: string;
|
||||
readonly configResolve: Effect.Effect<DesktopBackendStartConfig>;
|
||||
readonly onReady?: () => Effect.Effect<void>;
|
||||
// Receives the *resolved* httpBaseUrl of the run that just became
|
||||
// ready. The window service uses this to decide what URL to load
|
||||
// (the WSL backend reports its distro IP, the Windows backend reports
|
||||
// 127.0.0.1). Splitting this off from configResolve avoids races
|
||||
// between "fired onReady" and "currentConfig already advanced".
|
||||
readonly onReady?: (httpBaseUrl: URL) => Effect.Effect<void>;
|
||||
readonly onShutdown?: () => Effect.Effect<void>;
|
||||
}
|
||||
|
||||
@@ -533,7 +538,7 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
|
||||
return;
|
||||
}
|
||||
|
||||
yield* spec.onReady?.() ?? Effect.void;
|
||||
yield* spec.onReady?.(config.httpBaseUrl) ?? Effect.void;
|
||||
}),
|
||||
onReadinessFailure: (error) =>
|
||||
logInstanceWarning("backend readiness check failed during bootstrap", {
|
||||
|
||||
@@ -216,7 +216,8 @@ export const layer = Layer.effect(
|
||||
// swallowed here on purpose: they're logged by the window service
|
||||
// and we don't want a stuck splash window to block the readiness
|
||||
// callback (which would prevent restartAttempt from being reset).
|
||||
onReady: () => desktopWindow.handleBackendReady.pipe(Effect.catch(() => Effect.void)),
|
||||
onReady: (httpBaseUrl) =>
|
||||
desktopWindow.handleBackendReady(httpBaseUrl).pipe(Effect.catch(() => Effect.void)),
|
||||
onShutdown: () => desktopWindow.handleBackendNotReady,
|
||||
});
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ const makeDesktopWindowLayer = (selectedAction: Deferred.Deferred<string>) =>
|
||||
revealOrCreateMain: Effect.die("unexpected revealOrCreateMain"),
|
||||
activate: Effect.void,
|
||||
createMainIfBackendReady: Effect.void,
|
||||
handleBackendReady: Effect.void,
|
||||
handleBackendReady: () => Effect.void,
|
||||
handleBackendNotReady: Effect.void,
|
||||
dispatchMenuAction: (action) => Deferred.succeed(selectedAction, action).pipe(Effect.asVoid),
|
||||
syncAppearance: Effect.void,
|
||||
|
||||
@@ -168,7 +168,7 @@ describe("DesktopWindow", () => {
|
||||
yield* desktopWindow.activate;
|
||||
assert.equal(yield* Ref.get(createCount), 0);
|
||||
|
||||
yield* desktopWindow.handleBackendReady;
|
||||
yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
|
||||
assert.equal(yield* Ref.get(createCount), 1);
|
||||
assert.deepEqual(fakeWindow.loadURL.mock.calls[0], ["http://127.0.0.1:5733/"]);
|
||||
assert.equal(fakeWindow.openDevTools.mock.calls.length, 1);
|
||||
|
||||
@@ -54,7 +54,14 @@ export interface DesktopWindowShape {
|
||||
readonly revealOrCreateMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
|
||||
readonly activate: Effect.Effect<void, DesktopWindowError>;
|
||||
readonly createMainIfBackendReady: Effect.Effect<void, DesktopWindowError>;
|
||||
readonly handleBackendReady: Effect.Effect<void, DesktopWindowError>;
|
||||
// The pool tells us not just "primary backend is ready" but also
|
||||
// *where* the renderer should load from. In wsl-only mode that's the
|
||||
// WSL distro IP (e.g. http://172.27.152.141:3773), not the local
|
||||
// exposure URL — wslhost localhost forwarding is unreliable enough
|
||||
// that pointing loadURL at 127.0.0.1 breaks the renderer on hosts
|
||||
// where the forward isn't set up. The Windows-primary path passes
|
||||
// the same URL serverExposure would have given us.
|
||||
readonly handleBackendReady: (httpBaseUrl: URL) => Effect.Effect<void, DesktopWindowError>;
|
||||
// Called when the backend transitions back to "not ready" (clean stop,
|
||||
// restart, crash). Clears the latch that lets `activate` auto-create a
|
||||
// window so a "macOS dock click" while the backend is down doesn't
|
||||
@@ -161,6 +168,11 @@ const make = Effect.gen(function* () {
|
||||
// createMainIfBackendReady, which gates the post-readiness window
|
||||
// open in development and the macOS "activate without windows" path.
|
||||
const backendReadyRef = yield* Ref.make(false);
|
||||
// Renderer URL the primary backend told us to load. Populated by
|
||||
// handleBackendReady. createMain prefers this over serverExposure's
|
||||
// backendConfig because in wsl-only mode the primary doesn't bind on
|
||||
// the local exposure URL — the WSL backend listens on the distro IP.
|
||||
const backendHttpUrlRef = yield* Ref.make<Option.Option<URL>>(Option.none());
|
||||
const context = yield* Effect.context<DesktopWindowRuntimeServices>();
|
||||
const runPromise = Effect.runPromiseWith(context);
|
||||
|
||||
@@ -299,8 +311,11 @@ const make = Effect.gen(function* () {
|
||||
});
|
||||
|
||||
const createMain = Effect.gen(function* () {
|
||||
const backendConfig = yield* serverExposure.backendConfig;
|
||||
const window = yield* createWindow(backendConfig.httpBaseUrl);
|
||||
const reportedHttpUrl = yield* Ref.get(backendHttpUrlRef);
|
||||
const httpUrl = Option.isSome(reportedHttpUrl)
|
||||
? reportedHttpUrl.value
|
||||
: (yield* serverExposure.backendConfig).httpBaseUrl;
|
||||
const window = yield* createWindow(httpUrl);
|
||||
yield* electronWindow.setMain(window);
|
||||
yield* logWindowInfo("main window created");
|
||||
return window;
|
||||
@@ -341,14 +356,16 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
}).pipe(Effect.withSpan("desktop.window.activate")),
|
||||
createMainIfBackendReady,
|
||||
handleBackendReady: Effect.gen(function* () {
|
||||
handleBackendReady: Effect.fn("desktop.window.handleBackendReady")(function* (httpBaseUrl) {
|
||||
yield* Ref.set(backendHttpUrlRef, Option.some(httpBaseUrl));
|
||||
yield* Ref.set(backendReadyRef, true);
|
||||
yield* logWindowInfo("backend ready", { source: "http" });
|
||||
yield* logWindowInfo("backend ready", { source: "http", url: httpBaseUrl.href });
|
||||
yield* createMainIfBackendReady;
|
||||
}).pipe(Effect.withSpan("desktop.window.handleBackendReady")),
|
||||
handleBackendNotReady: Ref.set(backendReadyRef, false).pipe(
|
||||
Effect.withSpan("desktop.window.handleBackendNotReady"),
|
||||
),
|
||||
}),
|
||||
handleBackendNotReady: Effect.gen(function* () {
|
||||
yield* Ref.set(backendReadyRef, false);
|
||||
yield* Ref.set(backendHttpUrlRef, Option.none());
|
||||
}).pipe(Effect.withSpan("desktop.window.handleBackendNotReady")),
|
||||
dispatchMenuAction: Effect.fn("desktop.window.dispatchMenuAction")(function* (action) {
|
||||
yield* Effect.annotateCurrentSpan({ action });
|
||||
const existingWindow = yield* electronWindow.focusedMainOrFirst;
|
||||
|
||||
Reference in new issue
Block a user