authorgravatar for 97427849+flamboh@users.noreply.github.comoliver <97427849+flamboh@users.noreply.github.com> 2026-10-10 05:23:40-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-10 07:23:40-05:00
logf7664fdf425555e0f85b74d904cfa4eaf57cf7af
treed9fc84c4c4070d6e362bee5f43efa9d1c1c13c9e
parent8bf0a38873aed486a585b2cebd8dd577ae5656b3
signature Signed by PGP key B5690EEEBB952194

perf(web): Open Source Licenses downloads its manifest once per session (#17119)


1 files changed, 37 insertions(+), 13 deletions(-)

apps/web/src/components/settings/OpenSourceLicenses.tsx+37-13
......@@ -21,15 +21,35 @@ type LicenseManifestState =
2121 | { readonly status: "error"; readonly message: string }
2222 | { readonly status: "ready"; readonly manifest: ThirdPartyLicenseManifest };
2323
24async function loadLicenseManifest(signal: AbortSignal): Promise<ThirdPartyLicenseManifest> {
25 const response = await fetch(
26 `${import.meta.env.BASE_URL.replace(/\/$/, "")}/third-party-licenses.json`,
27 { signal },
28 );
29 if (!response.ok) {
30 throw new Error(`The license manifest request failed with status ${String(response.status)}.`);
24let licenseManifestPromise: Promise<ThirdPartyLicenseManifest> | undefined;
25
26async function fetchLicenseManifest(): Promise<ThirdPartyLicenseManifest> {
27 const signal = AbortSignal.timeout(30_000);
28 try {
29 const response = await fetch(
30 `${import.meta.env.BASE_URL.replace(/\/$/, "")}/third-party-licenses.json`,
31 { signal },
32 );
33 if (!response.ok) {
34 throw new Error(
35 `The license manifest request failed with status ${String(response.status)}.`,
36 );
37 }
38 return decodeThirdPartyLicenseManifest((await response.json()) as unknown);
39 } catch (error) {
40 if (signal.aborted) {
41 throw new Error("The license manifest took too long to load.", { cause: error });
42 }
43 throw error;
3144 }
32 return decodeThirdPartyLicenseManifest((await response.json()) as unknown);
45}
46
47function loadLicenseManifest(): Promise<ThirdPartyLicenseManifest> {
48 licenseManifestPromise ??= fetchLicenseManifest().catch((error: unknown) => {
49 licenseManifestPromise = undefined;
50 throw error;
51 });
52 return licenseManifestPromise;
3353}
3454
3555function LicenseNoticeRow({
......@@ -198,19 +218,23 @@ export function OpenSourceLicensesPanel() {
198218 const [requestVersion, setRequestVersion] = useState(0);
199219
200220 useEffect(() => {
201 const controller = new AbortController();
221 let cancelled = false;
202222 setState({ status: "loading" });
203 void loadLicenseManifest(controller.signal).then(
204 (manifest) => setState({ status: "ready", manifest }),
223 void loadLicenseManifest().then(
224 (manifest) => {
225 if (!cancelled) setState({ status: "ready", manifest });
226 },
205227 (error: unknown) => {
206 if (controller.signal.aborted) return;
228 if (cancelled) return;
207229 setState({
208230 status: "error",
209231 message: error instanceof Error ? error.message : "The license manifest could not load.",
210232 });
211233 },
212234 );
213 return () => controller.abort();
235 return () => {
236 cancelled = true;
237 };
214238 }, [requestVersion]);
215239
216240 const entries = state.status === "ready" ? state.manifest.entries : [];