Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
perf(updater): defer initial app update check until after first paint
Akarshan Biswase82108697a55
diff --git a/web-app/src/providers/DataProvider.tsx b/web-app/src/providers/DataProvider.tsxindex ebe3cb01c..390c42ac9 100644--- a/web-app/src/providers/DataProvider.tsx+++ b/web-app/src/providers/DataProvider.tsx@@ -197,8 +197,13 @@ export function DataProvider() {return}- // Initial check on mount- checkForUpdate()+ // Defer the initial check until the browser is idle (after first paint) so+ // the network round-trip and any resulting dialog don't compete with the+ // initial render.+ const ric = window.requestIdleCallback+ const idleHandle = ric+ ? ric(() => checkForUpdate(), { timeout: 3000 })+ : window.setTimeout(() => checkForUpdate(), 0)// Set up periodic update checks (singleton - only runs in DataProvider)const intervalId = setInterval(() => {@@ -208,6 +213,8 @@ export function DataProvider() {// Cleanup interval on unmountreturn () => {+ if (ric) window.cancelIdleCallback(idleHandle as number)+ else window.clearTimeout(idleHandle as number)clearInterval(intervalId)}}, [checkForUpdate, autoUpdateCheck])diff --git a/web-app/src/providers/__tests__/DataProvider.test.tsx b/web-app/src/providers/__tests__/DataProvider.test.tsxindex 2316d7005..78a8e8190 100644--- a/web-app/src/providers/__tests__/DataProvider.test.tsx+++ b/web-app/src/providers/__tests__/DataProvider.test.tsx@@ -350,10 +350,15 @@ describe('DataProvider', () => {expect(h.checkForUpdate).not.toHaveBeenCalled()})- it('runs initial update check and schedules periodic checks outside dev', async () => {+ it('defers initial update check off mount and schedules periodic checks outside dev', async () => {vi.useFakeTimers()h.isDev.mockReturnValue(false)render(<DataProvider />)+ // Initial check is deferred to idle (setTimeout fallback in jsdom), not on mount+ expect(h.checkForUpdate).not.toHaveBeenCalled()+ await act(async () => {+ vi.advanceTimersByTime(1)+ })expect(h.checkForUpdate).toHaveBeenCalledTimes(1)await act(async () => {vi.advanceTimersByTime(60_000)