perf(frontend): lazy-load heavy components to shrink initial bundle
Defer loading components that are off the initial render path until they
are first needed, keeping them out of the bundle that loads on page entry.
- Add `lazyComponent` composable: a tiny rune-based holder that dynamic-
imports a component on first `load()` and exposes it for `{@const}`
rendering, with the component type inferred from the module so prop/
binding type-checking stays intact.
- CommandPalette: loaded on the first Cmd/Ctrl+K and mounted open via a
new `autoOpen` prop. It was previously imported by AppShell, i.e. in the
initial chunk of every authenticated route (~27 KB). AppShell now owns
the shortcut that triggers the load.
- FileViewer + WopiEditor: loaded when a preview/editor first opens, across
files, recent, favorites and shared-with-me.
- PhotoLightbox / PlacesMap / PeopleView: loaded on first lightbox open or
when the places/people tab is selected (the latter also defers maplibre).
Once loaded a component stays mounted and behaves exactly as before, so
behavior is unchanged on the second use onward.
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
run: () => void;
|
||||
}
|
||||
|
||||
// `autoOpen` lets a lazy host (AppShell) mount us already-open on the first
|
||||
// Cmd/Ctrl+K, since our own key listener only exists once we're mounted.
|
||||
let { autoOpen = false }: { autoOpen?: boolean } = $props();
|
||||
|
||||
let open = $state(false);
|
||||
// Drives the enter animation: flipped on after mount so the overlay/panel
|
||||
// transition from their initial (faded/offset) state.
|
||||
@@ -30,6 +34,18 @@
|
||||
// Element focused before the palette opened, restored on close.
|
||||
let prevFocus: HTMLElement | null = null;
|
||||
|
||||
// When mounted already-open (autoOpen), run the same enter sequence the
|
||||
// keyboard path uses. Guarded so it fires once, not on every reopen.
|
||||
let didAutoOpen = false;
|
||||
$effect(() => {
|
||||
if (didAutoOpen || !autoOpen) return;
|
||||
didAutoOpen = true;
|
||||
open = true;
|
||||
prevFocus = document.activeElement as HTMLElement | null;
|
||||
requestAnimationFrame(() => (entered = true));
|
||||
queueMicrotask(() => input?.focus());
|
||||
});
|
||||
|
||||
function close() {
|
||||
open = false;
|
||||
entered = false;
|
||||
|
||||
Reference in New Issue
Block a user