From 4b33458c4b56b5485502c7319d142cee2cda768f Mon Sep 17 00:00:00 2001 From: santastabber <197905764+santastabber@users.noreply.github.com> Date: Wed, 1 Jul 2026 05:29:34 +1000 Subject: [PATCH] fix(pwa): defer new-chat model hydration --- static/boot.js | 9 ++++++++- tests/test_new_chat_default_model_frontend.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/static/boot.js b/static/boot.js index a1b9074c..3b44b497 100644 --- a/static/boot.js +++ b/static/boot.js @@ -2764,7 +2764,14 @@ window._applyTitlebarProfileVisibility=_applyTitlebarProfileVisibility; if(pwaLaunchAction==='new-chat'){ try{ await newSession(true); - if(S.session) await _startBootModelDropdown(); + // New-chat PWA launches need the empty conversation visible immediately. + // Boot model hydration can take several seconds when /api/models falls + // into a cold provider-catalog rebuild; it is already safe to finish in + // the background because newSession() posted the configured default and + // rendered the session's authoritative model/provider. + if(S.session){ + try{Promise.resolve(_startBootModelDropdown()).catch(()=>{});}catch(_){} + } S._bootReady=true; syncTopbar();syncWorkspacePanelState();await renderSessionList();if(typeof startGatewaySSE==='function')startGatewaySSE();return; }catch(e){console.warn('[pwa] new-chat launch action failed', e);} diff --git a/tests/test_new_chat_default_model_frontend.py b/tests/test_new_chat_default_model_frontend.py index 6506447b..da960125 100644 --- a/tests/test_new_chat_default_model_frontend.py +++ b/tests/test_new_chat_default_model_frontend.py @@ -68,6 +68,19 @@ def test_hard_refresh_hydrates_saved_session_model_before_revealing_model_chip() ) +def test_pwa_new_chat_launch_does_not_block_first_paint_on_model_catalog(): + boot_js = Path("static/boot.js").read_text(encoding="utf-8") + launch_marker = "if(pwaLaunchAction==='new-chat'){" + assert launch_marker in boot_js + launch_branch = boot_js[boot_js.index(launch_marker) : boot_js.index("const savedLocal=localStorage.getItem", boot_js.index(launch_marker))] + assert "await newSession(true);" in launch_branch + assert "await _startBootModelDropdown();" not in launch_branch + assert "Promise.resolve(_startBootModelDropdown()).catch(()=>{})" in launch_branch + assert launch_branch.index("Promise.resolve(_startBootModelDropdown()).catch(()=>{})") < launch_branch.index("S._bootReady=true;"), ( + "PWA new-chat launches should kick model hydration in the background before revealing the empty chat" + ) + + def test_hard_refresh_injects_missing_active_session_model_option(): boot_js = Path("static/boot.js").read_text(encoding="utf-8") marker = "if(!applied&&sessionModelState&&typeof _ensureModelOptionInDropdown==='function')"