Repository navigation
perf(bundle): split posthog, the driver registry and secondary pages out of the initial chunk #1227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,36 @@ | ||
| import { displayText } from "../i18n/index"; | ||
| import { useEffect, useRef, useState, type ReactNode } from "react"; | ||
| import { lazy, Suspense, useEffect, useRef, useState, type ReactNode } from "react"; | ||
| import * as control from "../device/controller"; | ||
| import { ensureDisplayLocale } from "../i18n/index"; | ||
| import { interfaceThemeSlug } from "../features/settings/interface-preferences"; | ||
| import { AppSidebar, type DesktopPage } from "./AppSidebar"; | ||
| import { OverviewPage } from "../features/devices/OverviewPage"; | ||
| import { CaptureDialog } from "../features/capture/CaptureDialog"; | ||
| import { GamesPage } from "../features/games/GamesPage"; | ||
| import { HardwareTestPage } from "../features/hardware-test/HardwareTestPage"; | ||
| import { InterfaceSettings } from "../features/settings/InterfaceSettings"; | ||
| import { NewsBanner } from "../features/news/NewsBanner"; | ||
| import { PendingBar } from "./PendingBar"; | ||
| import { HelpPanel } from "./HelpPanel"; | ||
| import { ShareProfileDialog } from "../features/profiles/ShareProfileDialog"; | ||
| import { WhatsNewDialog } from "../features/news/WhatsNewDialog"; | ||
| import { ToastHost } from "./Toasts"; | ||
| import { useBridgeBatteryReporter } from "../features/bridge/useBridgeBatteryReporter"; | ||
| import { useBridgeProfileApplier } from "../features/bridge/useBridgeProfileApplier"; | ||
| import { useControl } from "./useControl"; | ||
| import { setSoundsEnabled } from "../platform/sound-manager"; | ||
| import { UiLocaleContext } from "../shared/ui-locale"; | ||
|
|
||
| // Secondary pages and dialogs load on demand: the control panel's first paint | ||
| // is the device view, so nothing behind a tab or a button belongs in the | ||
| // initial bundle. Each boundary below removed its module from main.js. | ||
| const InterfaceSettings = lazy(() => | ||
| import("../features/settings/InterfaceSettings").then((m) => ({ default: m.InterfaceSettings }))); | ||
| const HardwareTestPage = lazy(() => | ||
| import("../features/hardware-test/HardwareTestPage").then((m) => ({ default: m.HardwareTestPage }))); | ||
| const GamesPage = lazy(() => | ||
| import("../features/games/GamesPage").then((m) => ({ default: m.GamesPage }))); | ||
| const CaptureDialog = lazy(() => | ||
| import("../features/capture/CaptureDialog").then((m) => ({ default: m.CaptureDialog }))); | ||
| const ShareProfileDialog = lazy(() => | ||
| import("../features/profiles/ShareProfileDialog").then((m) => ({ default: m.ShareProfileDialog }))); | ||
| const WhatsNewDialog = lazy(() => | ||
| import("../features/news/WhatsNewDialog").then((m) => ({ default: m.WhatsNewDialog }))); | ||
|
|
||
| const SIDEBAR_KEY = "openmouse-sidebar-collapsed-v1"; | ||
|
|
||
| function initialSidebarCollapsed(): boolean { | ||
|
|
@@ -172,29 +182,43 @@ export function App(): ReactNode { | |
| <main className="om-main full-desktop-main"> | ||
| <NewsBanner locale={locale} /> | ||
| <div className="om-content full-desktop-content" ref={panel}> | ||
| {showingSettings ? ( | ||
| <InterfaceSettings snapshot={snapshot} /> | ||
| ) : page === "hardware-test" ? ( | ||
| <HardwareTestPage snapshot={snapshot} /> | ||
| ) : showingGames ? ( | ||
| <GamesPage snapshot={snapshot} /> | ||
| ) : ( | ||
| <OverviewPage | ||
| snapshot={snapshot} | ||
| onOpenCapture={() => setCaptureOpen(true)} | ||
| onShareProfile={() => setShareProfileOpen(true)} | ||
| /> | ||
| )} | ||
| <Suspense fallback={null}> | ||
| {showingSettings ? ( | ||
| <InterfaceSettings snapshot={snapshot} /> | ||
| ) : page === "hardware-test" ? ( | ||
| <HardwareTestPage snapshot={snapshot} /> | ||
| ) : showingGames ? ( | ||
| <GamesPage snapshot={snapshot} /> | ||
| ) : ( | ||
| <OverviewPage | ||
| snapshot={snapshot} | ||
| onOpenCapture={() => setCaptureOpen(true)} | ||
| onShareProfile={() => setShareProfileOpen(true)} | ||
| /> | ||
| )} | ||
| </Suspense> | ||
| <p className="app-live-region" role="status" aria-live="polite"> | ||
| {displayText(locale, snapshot.readStatus)} | ||
| </p> | ||
| </div> | ||
| <PendingBar snapshot={snapshot} /> | ||
| </main> | ||
|
|
||
| <CaptureDialog open={captureOpen} onClose={() => setCaptureOpen(false)} locale={locale} /> | ||
| <WhatsNewDialog open={whatsNewOpen} onClose={() => setWhatsNewOpen(false)} locale={locale} /> | ||
| <ShareProfileDialog open={shareProfileOpen} onClose={() => setShareProfileOpen(false)} snapshot={snapshot} /> | ||
| {captureOpen ? ( | ||
| <Suspense fallback={null}> | ||
| <CaptureDialog open onClose={() => setCaptureOpen(false)} locale={locale} /> | ||
| </Suspense> | ||
| ) : null} | ||
|
Comment on lines
+207
to
+211
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔎 Supported by static analysis
Preserve the capture snapshot when the dialog closes.
Suggested fix
|
||
| {whatsNewOpen ? ( | ||
| <Suspense fallback={null}> | ||
| <WhatsNewDialog open onClose={() => setWhatsNewOpen(false)} locale={locale} /> | ||
| </Suspense> | ||
| ) : null} | ||
| {shareProfileOpen ? ( | ||
| <Suspense fallback={null}> | ||
| <ShareProfileDialog open onClose={() => setShareProfileOpen(false)} snapshot={snapshot} /> | ||
| </Suspense> | ||
| ) : null} | ||
| <HelpPanel locale={locale} /> | ||
| <ToastHost toasts={snapshot.toasts} locale={locale} /> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2740,18 +2740,18 @@ function sidebarEntryForm(client: SupportedClient): "mouse" | "keyboard" { | |
| } | ||
|
|
||
| /** One sidebar card per physical device, marking the active one. */ | ||
| function sidebarEntries(devices: HIDDevice[]): SidebarDevice[] { | ||
| const groups = logicalDeviceGroups(devices); | ||
| async function sidebarEntries(devices: HIDDevice[]): Promise<SidebarDevice[]> { | ||
| const groups = await logicalDeviceGroups(devices); | ||
| const entries: SidebarDevice[] = []; | ||
| for (let index = 0; index < groups.length; index += 1) { | ||
| const group = groups[index]; | ||
| const activeMember = group.find((member) => member === activeDevice); | ||
| const device = activeMember ?? pickLogicalDevice(group); | ||
| const device = activeMember ?? await pickLogicalDevice(group); | ||
| const transport = (device as HIDDevice & { openMouseTransport?: string }).openMouseTransport === "bridge" | ||
| ? "bridge" | ||
| : "webhid"; | ||
| const selected = group.some((member) => member === activeDevice); | ||
| const client = createSupportedClient(device); | ||
| const client = await createSupportedClient(device); | ||
| if (!client) { | ||
| const keyboard = createKeyboardClient(device); | ||
| if (!keyboard) continue; | ||
|
|
@@ -2777,10 +2777,10 @@ function sidebarEntries(devices: HIDDevice[]): SidebarDevice[] { | |
| ? EGG_WE_DISPLAY_NAME | ||
| : client instanceof FinalmouseHidClient | ||
| ? client.displayName() | ||
| : (device.productName ?? `${deviceBrand(client)} mouse`)); | ||
| : (device.productName ?? `${await deviceBrand(client)} mouse`)); | ||
| const detail = status | ||
| ? `${status.brand} · ${connectionText(interfacePreferences.locale, status.connectionType, "ctl.connected")}` | ||
| : `${deviceBrand(client)} · Available`; | ||
| : `${await deviceBrand(client)} · Available`; | ||
| entries.push({ | ||
| index, | ||
| name, | ||
|
|
@@ -2808,7 +2808,7 @@ async function refreshSidebar(devices?: HIDDevice[]): Promise<void> { | |
| return; | ||
| } | ||
| } | ||
| sidebarDevices = sidebarEntries(all); | ||
| sidebarDevices = await sidebarEntries(all); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent an older sidebar refresh from replacing a newer list. If two refreshes overlap, the first can finish last because
|
||
| emit(); | ||
| } | ||
|
|
||
|
|
@@ -2879,8 +2879,10 @@ export async function selectAuthorizedDevice(index: number): Promise<void> { | |
| const group = groups[index]; | ||
| if (!group) return; | ||
| if (group.some((device) => device === activeDevice) && (latestDeviceStatus !== null || activeKeyboard !== null)) return; | ||
| const candidates = group | ||
| .map((device) => ({ client: createSupportedClient(device), score: clientSupportScore(device) })) | ||
| const candidates = (await Promise.all(group.map(async (device) => ({ | ||
| client: await createSupportedClient(device), | ||
| score: await clientSupportScore(device), | ||
| })))) | ||
| .filter((entry): entry is { client: SupportedClient; score: number } => entry.client !== null) | ||
| .sort((left, right) => right.score - left.score); | ||
| if (candidates.length === 0) { | ||
|
|
@@ -3623,14 +3625,14 @@ function handleHidConnect(event: HIDConnectionEvent): void { | |
| void refreshSidebar(); | ||
| return; | ||
| } | ||
| const client = createSupportedClient(event.device); | ||
| if (!client) { | ||
| void refreshSidebar(); | ||
| return; | ||
| } | ||
| void (async () => { | ||
| const client = await createSupportedClient(event.device); | ||
| if (!client) { | ||
| void refreshSidebar(); | ||
| return; | ||
| } | ||
|
|
||
| if (isEggWeClient(client)) { | ||
| void (async () => { | ||
| if (isEggWeClient(client)) { | ||
| const all = await navigator.hid?.getDevices() ?? []; | ||
| await refreshSidebar(all); | ||
| const result = await eggWeResolveConnect(event.device, eggWeClient(), activeDevice, all); | ||
|
|
@@ -3651,16 +3653,11 @@ function handleHidConnect(event: HIDConnectionEvent): void { | |
| : st("ctl.reading", { name: EGG_WE_DISPLAY_NAME }); | ||
| emit(); | ||
| await activateClient(result.client); | ||
| })().catch((error: unknown) => { | ||
| deviceStatusText = st("ctl.connFailed"); | ||
| readStatus = error instanceof Error ? error.message : st("ctl.unableRead"); | ||
| toastForError("Connection failed", error); | ||
| void refreshSidebar(); | ||
| }); | ||
| return; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| void activateClient(client, true).catch((error: unknown) => { | ||
| await activateClient(client, true); | ||
| })().catch((error: unknown) => { | ||
| deviceStatusText = st("ctl.connFailed"); | ||
| readStatus = error instanceof Error ? error.message : st("ctl.unableRead"); | ||
| toastForError("Connection failed", error); | ||
|
|
@@ -3681,9 +3678,8 @@ function handleHidDisconnect(event: HIDConnectionEvent): void { | |
| void (async () => { | ||
| const devices = (await navigator.hid?.getDevices() ?? []) | ||
| .filter((device) => device !== event.device); | ||
| const logical = listLogicalDevices(devices); | ||
| const replacement = logical | ||
| .map(createSupportedClient) | ||
| const logical = await listLogicalDevices(devices); | ||
| const replacement = (await Promise.all(logical.map((device) => createSupportedClient(device)))) | ||
| .find((client): client is SupportedClient => client !== null); | ||
| if (replacement) { | ||
| await activateClient(replacement); | ||
|
|
@@ -3724,8 +3720,11 @@ async function requestSupportedClient( | |
| if (weClient) return weClient; | ||
| } | ||
|
|
||
| const ranked = devices | ||
| .map((device) => ({ device, client: createSupportedClient(device), score: clientSupportScore(device) })) | ||
| const ranked = (await Promise.all(devices.map(async (device) => ({ | ||
| device, | ||
| client: await createSupportedClient(device), | ||
| score: await clientSupportScore(device), | ||
| })))) | ||
| .filter((entry) => entry.client !== null) | ||
| .sort((left, right) => right.score - left.score); | ||
| const best = ranked[0]; | ||
|
|
@@ -3877,16 +3876,15 @@ async function reconnectAuthorizedDevice(): Promise<void> { | |
| // authorized, and multiple keyboards must respect the saved preference | ||
| // too. Mice keep the first slot when nothing is preferred, which was the | ||
| // behavior before keyboards joined the reconnect path. | ||
| const candidates = listLogicalDevices(devices) | ||
| .map((device) => { | ||
| const client = createSupportedClient(device) ?? createKeyboardClient(device); | ||
| return client === null ? null : { | ||
| client, | ||
| preferred: deviceStorageKey(device) === preferredKey, | ||
| keyboard: isKeyboardClient(client), | ||
| score: clientSupportScore(device), | ||
| }; | ||
| }) | ||
| const candidates = (await Promise.all((await listLogicalDevices(devices)).map(async (device) => { | ||
| const client = await createSupportedClient(device) ?? createKeyboardClient(device); | ||
| return client === null ? null : { | ||
| client, | ||
| preferred: deviceStorageKey(device) === preferredKey, | ||
| keyboard: isKeyboardClient(client), | ||
| score: await clientSupportScore(device), | ||
| }; | ||
| }))) | ||
| .filter((entry): entry is { client: SupportedClient | KeyboardClient; preferred: boolean; keyboard: boolean; score: number } => entry !== null) | ||
| .sort((left, right) => Number(right.preferred) - Number(left.preferred) | ||
| || Number(left.keyboard) - Number(right.keyboard) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail when no main chunk matches.
If the entry chunk is renamed, this filter selects no assets.
mainBytesthen becomes0, and the size check reports success without checking the entry chunk. Reject an empty match before reporting that the main bundle is within budget.