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
@@ -75,6 +75,7 @@ export async function fetchBootstrap(
|
||||
const res = await fetchWithTimeout(`${baseUrl}/webui/bootstrap`, {
|
||||
method: "GET",
|
||||
credentials: "same-origin",
|
||||
cache: "no-store",
|
||||
headers,
|
||||
}, timeoutMs);
|
||||
if (!res.ok) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { consumeUrlBootstrapSecret, fetchBootstrap, loadSavedSecret } from "./bootstrap";
|
||||
|
||||
export async function requestBootstrap(secret = consumeUrlBootstrapSecret() || loadSavedSecret()) {
|
||||
const boot = await fetchBootstrap("", secret);
|
||||
// The document can receive the token well before React mounts. Do not extend its TTL.
|
||||
const tokenExpiresAt = boot.expires_in ? Date.now() + Math.max(0, boot.expires_in) * 1000 : null;
|
||||
return { boot, secret, tokenExpiresAt };
|
||||
}
|
||||
|
||||
export type BootstrapRequest = ReturnType<typeof requestBootstrap>;
|
||||
|
||||
/** Hand this document's request to its App, not to a global or persistent cache. */
|
||||
export function preloadInitialBootstrap() {
|
||||
let pending: BootstrapRequest | undefined = requestBootstrap();
|
||||
// A fast 401 (or timeout) may arrive before the UI imports. App handles the original rejection.
|
||||
void pending.catch(() => {});
|
||||
return () => {
|
||||
const request = pending;
|
||||
pending = undefined;
|
||||
return request;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user