fix(desktop): boot the main window unthrottled so cold start paints at full speed (#7460)

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 authored and GitHub committed 2026-08-18 21:29:02 -04:00
1 parent e7f6a30cab
commit efcf7d1ac0
2 files changed
+43 -1

No files matched your search

+32 -1
View File
@@ -80,6 +80,7 @@ function makeFakeBrowserWindow() {
reload: vi.fn(),
replaceMisspelling: vi.fn(),
send: vi.fn(),
setBackgroundThrottling: vi.fn(),
setWindowOpenHandler: vi.fn(),
};
@@ -124,6 +125,7 @@ function makeFakeBrowserWindow() {
reload: webContents.reload,
send: webContents.send,
setZoomLevel: webContents.setZoomLevel,
setBackgroundThrottling: webContents.setBackgroundThrottling,
setAutoHideCursor: window.setAutoHideCursor,
webContentsListeners,
windowListeners,
@@ -455,7 +457,7 @@ describe("DesktopWindow", () => {
assert.isUndefined(createdWindowOptions[0]?.x);
assert.isUndefined(createdWindowOptions[0]?.y);
assert.isTrue(createdWindowOptions[0]?.disableAutoHideCursor);
assert.isUndefined(createdWindowOptions[0]?.webPreferences?.backgroundThrottling);
assert.isFalse(createdWindowOptions[0]?.webPreferences?.backgroundThrottling);
assert.deepEqual(fakeWindow.setAutoHideCursor.mock.calls, [[false]]);
assert.deepEqual(fakeWindow.loadURL.mock.calls[0], ["t3code-dev://app/"]);
assert.equal(fakeWindow.openDevTools.mock.calls.length, 1);
@@ -604,6 +606,35 @@ describe("DesktopWindow", () => {
}),
);
// The window boots hidden with throttling disabled so first paint runs at
// full speed; the first reveal must hand it back to normal hidden-window
// throttling or a minimized window stays expensive forever.
it.effect("re-enables background throttling on first reveal", () =>
Effect.gen(function* () {
const fakeWindow = makeFakeBrowserWindow();
const createCount = yield* Ref.make(0);
const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
const layer = makeTestLayer({
window: fakeWindow.window,
createCount,
mainWindow,
});
yield* Effect.gen(function* () {
const desktopWindow = yield* DesktopWindow.DesktopWindow;
yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
assert.equal(fakeWindow.setBackgroundThrottling.mock.calls.length, 0);
const readyToShow = fakeWindow.windowListeners.get("ready-to-show");
if (!readyToShow) {
return yield* Effect.die("window ready-to-show listener was not registered");
}
readyToShow();
assert.deepEqual(fakeWindow.setBackgroundThrottling.mock.calls, [[true]]);
}).pipe(Effect.provide(layer));
}),
);
it.effect("debounces move and resize bounds updates", () =>
Effect.gen(function* () {
const fakeWindow = makeFakeBrowserWindow();
+11
View File
@@ -359,6 +359,12 @@ export const make = Effect.gen(function* () {
...getWindowTitleBarOptions(shouldUseDarkColors, environment.platform),
webPreferences: {
preload: environment.preloadPath,
// The window boots hidden (show: false until ready-to-show), and
// Chromium throttles hidden renderers: timers coalesce and rAF stops,
// which stalls first paint. Boot unthrottled; the first-reveal trigger
// re-enables throttling so a hidden or minimized window goes back to
// being cheap after it has been shown once.
backgroundThrottling: false,
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
@@ -725,6 +731,11 @@ export const make = Effect.gen(function* () {
revealSubscribers.push((fire) => window.webContents.once("did-finish-load", fire));
}
bindFirstRevealTrigger(revealSubscribers, () => {
// Boot is done; hand the window back to normal hidden-window throttling
// (see the backgroundThrottling comment on the create options above).
if (!window.isDestroyed()) {
window.webContents.setBackgroundThrottling(true);
}
// Reveal the real window, then close the connecting splash (if any) so the
// two don't overlap and there's no blank gap between them.
if (persistedSettings.mainWindowMaximized) {