Centralize on preload naming for lazy component loading

Reverts the earlier preload->prefetch rename of the LazyComponent API
and aligns the new route map and hover preloading with the existing
preload terminology instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W45zR5AhPpLURRoDQUsAgX
This commit is contained in:
Claude committed 2026-07-15 22:58:54 +00:00
1 parent bc14006f79
commit 50ca7baf2d
8 files changed
+43 -43

No files matched your search

+2 -2
View File
@@ -121,9 +121,9 @@ export const CollectionForm = observer(function CollectionForm_({
const values = watch();
// Prefetch the IconPicker component on mount
// Preload the IconPicker component on mount
useEffect(() => {
void IconPicker.prefetch();
void IconPicker.preload();
}, []);
useEffect(() => {
+4 -4
View File
@@ -4,7 +4,7 @@ import lazyWithRetry from "~/utils/lazyWithRetry";
// oxlint-disable no-explicit-any -- ComponentType<any> is the standard React pattern for generic component constraints
export interface LazyComponent<T extends React.ComponentType<any>> {
Component: React.LazyExoticComponent<T>;
prefetch: () => Promise<{ default: T }>;
preload: () => Promise<{ default: T }>;
}
interface LazyLoadOptions {
@@ -15,12 +15,12 @@ interface LazyLoadOptions {
}
/**
* Creates a lazy-loaded component with prefetching capability and automatic retries on failure.
* Creates a lazy-loaded component with preloading capability and automatic retries on failure.
* Supports both default and named exports.
*
* @param factory A function that returns a promise of a module.
* @param options Optional configuration for retry behavior and export name.
* @returns An object containing the lazy Component and a prefetch function.
* @returns An object containing the lazy Component and a preload function.
*
* @example
* ```typescript
@@ -48,6 +48,6 @@ export function createLazyComponent<T extends React.ComponentType<any>>(
return {
Component: lazyWithRetry(wrappedFactory, retries, interval),
prefetch: wrappedFactory,
preload: wrappedFactory,
};
}
+1 -1
View File
@@ -56,7 +56,7 @@ const ReactionPicker: React.FC<Props> = ({ onSelect, className, size }) => {
<NudeButton
aria-label={t("Reaction picker")}
className={className}
onMouseEnter={() => EmojiPanel.prefetch()}
onMouseEnter={() => EmojiPanel.preload()}
onClick={(e) => e.stopPropagation()}
size={size}
>
+1 -1
View File
@@ -56,7 +56,7 @@ function SettingsSidebar() {
<SidebarLink
key={item.path}
to={item.path}
onClickIntent={item.prefetch}
onClickIntent={item.preload}
active={
item.path.startsWith(settingsPath("templates")) ||
item.path.startsWith(settingsPath("groups"))
@@ -8,7 +8,7 @@ import { isMobile } from "@shared/utils/browser";
import NudeButton from "~/components/NudeButton";
import { UnreadBadge } from "~/components/UnreadBadge";
import useClickIntent from "~/hooks/useClickIntent";
import { prefetchRouteComponents } from "~/routes/prefetch";
import { preloadRouteComponents } from "~/routes/preload";
import { undraggableOnDesktop } from "~/styles";
import Disclosure from "./Disclosure";
import type { Props as NavLinkProps } from "./NavLink";
@@ -106,10 +106,10 @@ function SidebarLink(
(ev: React.MouseEvent<HTMLElement>) => {
onClickIntent?.(ev);
// In addition to any data prefetch, warm the code-split chunks for the
// route the link points to.
// In addition to any data prefetch, preload the code-split chunks for
// the route the link points to.
if (to) {
prefetchRouteComponents(to);
preloadRouteComponents(to);
}
},
[onClickIntent, to]
+21 -21
View File
@@ -60,7 +60,7 @@ export type ConfigItem = {
}>;
component: React.ComponentType;
description?: string;
prefetch?: () => void;
preload?: () => void;
enabled: boolean;
group: string;
pluginId?: string;
@@ -84,7 +84,7 @@ const useSettingsConfig = () => {
name: t("Profile"),
path: settingsPath(),
component: Profile.Component,
prefetch: Profile.prefetch,
preload: Profile.preload,
enabled: true,
group: t("Account"),
icon: ProfileIcon,
@@ -93,7 +93,7 @@ const useSettingsConfig = () => {
name: t("Preferences"),
path: settingsPath("preferences"),
component: Preferences.Component,
prefetch: Preferences.prefetch,
preload: Preferences.preload,
enabled: true,
group: t("Account"),
icon: SettingsIcon,
@@ -102,7 +102,7 @@ const useSettingsConfig = () => {
name: t("Notifications"),
path: settingsPath("notifications"),
component: Notifications.Component,
prefetch: Notifications.prefetch,
preload: Notifications.preload,
enabled: true,
group: t("Account"),
icon: EmailIcon,
@@ -111,7 +111,7 @@ const useSettingsConfig = () => {
name: t("API & Access"),
path: settingsPath("api-and-access"),
component: APIAndAccess.Component,
prefetch: APIAndAccess.prefetch,
preload: APIAndAccess.preload,
enabled: true,
group: t("Account"),
icon: PadlockIcon,
@@ -121,7 +121,7 @@ const useSettingsConfig = () => {
name: t("Details"),
path: settingsPath("details"),
component: Details.Component,
prefetch: Details.prefetch,
preload: Details.preload,
enabled: can.update,
group: t("Workspace"),
icon: TeamIcon,
@@ -130,7 +130,7 @@ const useSettingsConfig = () => {
name: t("Authentication"),
path: settingsPath("authentication"),
component: Authentication.Component,
prefetch: Authentication.prefetch,
preload: Authentication.preload,
enabled: can.update,
group: t("Workspace"),
icon: PadlockIcon,
@@ -139,7 +139,7 @@ const useSettingsConfig = () => {
name: t("Security"),
path: settingsPath("security"),
component: Security.Component,
prefetch: Security.prefetch,
preload: Security.preload,
enabled: can.update,
group: t("Workspace"),
icon: ShieldIcon,
@@ -148,7 +148,7 @@ const useSettingsConfig = () => {
name: t("AI"),
path: settingsPath("features"),
component: Features.Component,
prefetch: Features.prefetch,
preload: Features.preload,
enabled: can.update,
group: t("Workspace"),
icon: SparklesIcon,
@@ -157,7 +157,7 @@ const useSettingsConfig = () => {
name: t("Members"),
path: settingsPath("members"),
component: Members.Component,
prefetch: Members.prefetch,
preload: Members.preload,
enabled: can.listUsers,
group: t("Workspace"),
icon: UserIcon,
@@ -166,7 +166,7 @@ const useSettingsConfig = () => {
name: t("Groups"),
path: settingsPath("groups"),
component: Groups.Component,
prefetch: Groups.prefetch,
preload: Groups.preload,
enabled: can.listGroups,
group: t("Workspace"),
icon: GroupIcon,
@@ -175,7 +175,7 @@ const useSettingsConfig = () => {
name: t("Templates"),
path: settingsPath("templates"),
component: Templates.Component,
prefetch: Templates.prefetch,
preload: Templates.preload,
enabled: can.readTemplate,
group: t("Workspace"),
icon: ShapesIcon,
@@ -184,7 +184,7 @@ const useSettingsConfig = () => {
name: t("Emojis"),
path: settingsPath("emojis"),
component: CustomEmojis.Component,
prefetch: CustomEmojis.prefetch,
preload: CustomEmojis.preload,
enabled: can.update,
group: t("Workspace"),
icon: SmileyIcon,
@@ -193,7 +193,7 @@ const useSettingsConfig = () => {
name: t("API Keys"),
path: settingsPath("api-keys"),
component: ApiKeys.Component,
prefetch: ApiKeys.prefetch,
preload: ApiKeys.preload,
enabled: can.listApiKeys,
group: t("Workspace"),
icon: CodeIcon,
@@ -202,7 +202,7 @@ const useSettingsConfig = () => {
name: t("Applications"),
path: settingsPath("applications"),
component: Applications.Component,
prefetch: Applications.prefetch,
preload: Applications.preload,
enabled: can.listOAuthClients,
group: t("Workspace"),
icon: InternetIcon,
@@ -211,7 +211,7 @@ const useSettingsConfig = () => {
name: t("Shared Links"),
path: settingsPath("shares"),
component: Shares.Component,
prefetch: Shares.prefetch,
preload: Shares.preload,
enabled: can.listShares,
group: t("Workspace"),
icon: GlobeIcon,
@@ -220,7 +220,7 @@ const useSettingsConfig = () => {
name: t("Import"),
path: settingsPath("import"),
component: Import.Component,
prefetch: Import.prefetch,
preload: Import.preload,
enabled: can.createImport,
group: t("Workspace"),
icon: ImportIcon,
@@ -229,7 +229,7 @@ const useSettingsConfig = () => {
name: t("Export"),
path: settingsPath("export"),
component: Export.Component,
prefetch: Export.prefetch,
preload: Export.preload,
enabled: can.createExport,
group: t("Workspace"),
icon: ExportIcon,
@@ -239,7 +239,7 @@ const useSettingsConfig = () => {
name: t("Embeds"),
path: integrationSettingsPath("embeds"),
component: Embeds.Component,
prefetch: Embeds.prefetch,
preload: Embeds.preload,
description: t(
"Configure which embed providers are available in the editor."
),
@@ -251,7 +251,7 @@ const useSettingsConfig = () => {
name: `${t("Install")}…`,
path: settingsPath("integrations"),
component: Integrations.Component,
prefetch: Integrations.prefetch,
preload: Integrations.preload,
enabled: can.update,
group: t("Integrations"),
icon: PlusIcon,
@@ -274,7 +274,7 @@ const useSettingsConfig = () => {
pluginId: plugin.id,
description: plugin.value.description,
component: plugin.value.component.Component,
prefetch: plugin.value.component.prefetch,
preload: plugin.value.component.preload,
enabled: plugin.value.enabled
? plugin.value.enabled(team, user)
: can.update,
+6 -6
View File
@@ -18,7 +18,7 @@ import {
/**
* A lazy-loaded route in the application, pairing the path patterns it
* renders at with the code-split component and a way to prefetch it.
* renders at with the code-split component and a way to preload it.
*/
export interface RouteMapEntry {
/** Patterns, in react-router syntax, matching the locations the scene renders at. */
@@ -26,17 +26,17 @@ export interface RouteMapEntry {
/** The lazy-loaded component rendered for the route. */
Component: React.LazyExoticComponent<React.ComponentType<any>>;
/** Imports the code-split chunk(s) for the route ahead of render. */
prefetch: () => Promise<unknown>;
preload: () => Promise<unknown>;
}
/**
* The single source of truth for lazy-loaded routes that are reachable
* through in-app navigation. Route definitions (see `./index` and
* `./authenticated`) render `Component` at `paths`, and hovering a link is
* used as a signal to call `prefetch` (see `./prefetch`) so the code is
* used as a signal to call `preload` (see `./preload`) so the code is
* already available when the user navigates.
*
* Note: Prefetch matching checks entries in order and patterns are matched
* Note: Preload matching checks entries in order and patterns are matched
* non-exactly, so list more specific routes before routes they share a
* prefix with.
*/
@@ -64,10 +64,10 @@ function defineRoute(
paths: string | string[],
load: () => Promise<{ default: React.ComponentType<any> }>
): RouteMapEntry {
const { Component, prefetch } = createLazyComponent(load);
const { Component, preload } = createLazyComponent(load);
return {
paths: Array.isArray(paths) ? paths : [paths],
Component,
prefetch,
preload,
};
}
@@ -4,7 +4,7 @@ import env from "~/env";
import { routeMap } from "./map";
/**
* Prefetches the lazy-loaded components associated with the route that the
* Preloads the lazy-loaded components associated with the route that the
* given location resolves to, so the code is already available by the time
* the user navigates there.
*
@@ -13,7 +13,7 @@ import { routeMap } from "./map";
*
* @param to the location the user is expected to navigate to.
*/
export function prefetchRouteComponents(to: LocationDescriptor): void {
export function preloadRouteComponents(to: LocationDescriptor): void {
const path = typeof to === "string" ? to : to.pathname;
if (!path) {
return;
@@ -28,7 +28,7 @@ export function prefetchRouteComponents(to: LocationDescriptor): void {
paths.some((pattern) => matchPath(pathname, { path: pattern }))
);
void route?.prefetch().catch(() => {
// Prefetching is best effort.
void route?.preload().catch(() => {
// Preloading is best effort.
});
}