From 682adca6bb4615ab506625ecff02c1f5c9464cd6 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Thu, 23 Jul 2026 15:54:28 -0500 Subject: [PATCH] perf: split heavy room features from startup --- src/app/components/message/LocationMap.tsx | 45 +++++++++++++++++++ .../components/message/MsgTypeRenderers.tsx | 38 ++++------------ src/app/features/room/RoomInput.tsx | 32 +++++++++---- src/app/plugins/arborium/themes.ts | 6 +-- 4 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 src/app/components/message/LocationMap.tsx diff --git a/src/app/components/message/LocationMap.tsx b/src/app/components/message/LocationMap.tsx new file mode 100644 index 000000000..5a04ec93c --- /dev/null +++ b/src/app/components/message/LocationMap.tsx @@ -0,0 +1,45 @@ +import { Icon } from 'leaflet'; +import type { LatLngExpression } from 'leaflet'; +import markerIconPng from 'leaflet/dist/images/marker-icon.png'; +import 'leaflet/dist/leaflet.css'; +import { MapContainer, Marker, TileLayer } from 'react-leaflet'; + +const markerIcon = new Icon({ + iconUrl: markerIconPng, + iconSize: [25, 41], + iconAnchor: [12, 41], +}); + +type LocationMapProps = { + coordinates: [number, number]; + className?: string; +}; + +export function LocationMap({ coordinates, className }: LocationMapProps) { + const position: LatLngExpression = coordinates; + + return ( + + + { + event.originalEvent.preventDefault(); + event.originalEvent.stopPropagation(); + }, + }} + icon={markerIcon} + /> + + ); +} diff --git a/src/app/components/message/MsgTypeRenderers.tsx b/src/app/components/message/MsgTypeRenderers.tsx index 5f6cbeefd..c29150c87 100644 --- a/src/app/components/message/MsgTypeRenderers.tsx +++ b/src/app/components/message/MsgTypeRenderers.tsx @@ -1,4 +1,4 @@ -import { type CSSProperties, type ReactNode, useMemo } from 'react'; +import { lazy, Suspense, type CSSProperties, type ReactNode, useMemo } from 'react'; import { ArrowSquareOut, sizedIcon, Link } from '$components/icons/phosphor'; import { Box, Chip, Text, toRem } from 'folds'; import { type IContent, type IPreviewUrlResponse, type MatrixClient } from '$types/matrix-sdk'; @@ -38,14 +38,13 @@ import { LINKINPUTREGEX } from '$components/editor'; import { MATRIX_TO_BASE } from '$plugins/matrix-to'; import { copyToClipboard } from '$utils/dom'; import { getAttachmentFilename } from '$utils/download'; -import { MapContainer, Marker, TileLayer } from 'react-leaflet'; -import type { LatLngExpression } from 'leaflet'; -import 'leaflet/dist/leaflet.css'; - import * as css from './MsgTypeRenderers.css'; -import { markerIcon } from '$features/room/location-modal/LocationDialog'; import { isNumber } from 'matrix-js-sdk/lib/utils'; +const LocationMap = lazy(() => + import('./LocationMap').then((module) => ({ default: module.LocationMap })) +); + export interface BundleContent extends IPreviewUrlResponse { matched_url: string; } @@ -707,7 +706,7 @@ export function MLocation({ content, showMaps }: MLocationProps) { const location = parseGeoUri(geoUri); if (!location) return ; const isValid = isNumber(Number(location.latitude)) && isNumber(Number(location.longitude)); - const coords: LatLngExpression = [Number(location.latitude), Number(location.longitude)]; + const coordinates: [number, number] = [Number(location.latitude), Number(location.longitude)]; return ( {showMaps && isValid && ( - - - { - e.originalEvent.preventDefault(); - e.originalEvent.stopPropagation(); - }, - }} - icon={markerIcon} - /> - + + + )} ); diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 482b84801..4119b7eb1 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -1,5 +1,14 @@ import type { KeyboardEventHandler, MouseEvent, RefObject } from 'react'; -import { forwardRef, useCallback, useEffect, useRef, useState, useMemo } from 'react'; +import { + forwardRef, + lazy, + Suspense, + useCallback, + useEffect, + useRef, + useState, + useMemo, +} from 'react'; import { useAtom, useAtomValue, useSetAtom } from 'jotai'; import { isKeyHotkey } from 'is-hotkey'; @@ -192,10 +201,13 @@ import type { import { AudioMessageRecorder } from './AudioMessageRecorder'; import * as prefix from '$unstable/prefixes'; import { PollDialog } from './poll-modals'; -import { LocationDialog } from './location-modal'; import { useClientConfig } from '$hooks/useClientConfig'; import { PersonaPicker } from './persona-picker/PersonaPicker.tsx'; +const LocationDialog = lazy(() => + import('./location-modal').then((module) => ({ default: module.LocationDialog })) +); + // Returns the event ID of the most recent non-reaction/non-edit event in a thread, // falling back to the thread root if no replies exist yet. export const getLatestThreadEventId = (room: Room, threadRootId: string): string => { @@ -2139,13 +2151,15 @@ export const RoomInput = forwardRef( /> )} {showLocationPicker && ( - setShowLocationPicker(false)} - mx={mx} - room={room} - replyDraft={replyDraft} - clearReplyDraft={() => setReplyDraft(replyDraftBase)} - /> + + setShowLocationPicker(false)} + mx={mx} + room={room} + replyDraft={replyDraft} + clearReplyDraft={() => setReplyDraft(replyDraftBase)} + /> + )} ); diff --git a/src/app/plugins/arborium/themes.ts b/src/app/plugins/arborium/themes.ts index 5bd5de57d..059d178de 100644 --- a/src/app/plugins/arborium/themes.ts +++ b/src/app/plugins/arborium/themes.ts @@ -1,8 +1,8 @@ -import { pluginVersion } from '@arborium/arborium'; - export type ArboriumThemeKind = 'light' | 'dark'; -export const ARBORIUM_CDN_VERSION = pluginVersion; +// Keep this literal aligned with the installed package. The theme test compares it with +// Arborium's runtime export without pulling the syntax highlighter into the startup bundle. +export const ARBORIUM_CDN_VERSION = '2.18.1'; const ARBORIUM_THEME_DEFINITIONS = [ { id: 'alabaster', label: 'Alabaster', kind: 'light' },