perf(webui): batch startup recovery and authenticate before React (#6708)
This commit is contained in:
1 parent
9652302324
commit
273582916b
26 files changed
+537
-330
No files matched your search
+11
-7
@@ -1,8 +1,5 @@
|
||||
import ReactDOM from "react-dom/client";
|
||||
|
||||
import App from "./App";
|
||||
import "./globals.css";
|
||||
import { initializeI18n } from "./i18n";
|
||||
import { preloadInitialBootstrap } from "./lib/initial-bootstrap";
|
||||
import { initializePairReturn } from "./lib/remote-pair-return";
|
||||
|
||||
// `crypto.randomUUID` is only defined in secure contexts (HTTPS or localhost).
|
||||
@@ -28,6 +25,14 @@ initializePairReturn();
|
||||
window.addEventListener("hashchange", initializePairReturn);
|
||||
|
||||
async function renderWebui(container: HTMLElement) {
|
||||
const takeInitialBootstrap = preloadInitialBootstrap();
|
||||
const localeReady = import("./i18n").then(({ initializeI18n }) => initializeI18n());
|
||||
const app = import("./mount");
|
||||
// The HTML skeleton already resolved the initial route (including restart links).
|
||||
// Warm only code: neither chat nor a socket mounts until App accepts the bootstrap.
|
||||
if (container.querySelector('[data-startup-surface="chat"]')) {
|
||||
void import("./components/thread/ThreadShell").catch(() => {});
|
||||
}
|
||||
// The critical skeleton paints immediately; React must wait for the full stylesheet.
|
||||
const styles = [...document.querySelectorAll<HTMLLinkElement>("link[data-app-stylesheet]")]
|
||||
.map((link) => new Promise<void>((resolve, reject) => {
|
||||
@@ -38,9 +43,8 @@ async function renderWebui(container: HTMLElement) {
|
||||
link.rel = "stylesheet";
|
||||
if (link.sheet) ready();
|
||||
}));
|
||||
await Promise.all([initializeI18n(), ...styles]);
|
||||
/* StrictMode disabled: dev double-invokes state updaters; delta accumulation must stay pure — see useNanobotStream. */
|
||||
ReactDOM.createRoot(container).render(<App />);
|
||||
const [{ mountWebui }] = await Promise.all([app, localeReady, ...styles]);
|
||||
mountWebui(container, takeInitialBootstrap);
|
||||
}
|
||||
|
||||
void renderWebui(root);
|
||||
|
||||
Reference in new issue
Block a user