perf: split heavy room features from startup

This commit is contained in:
7w1 committed 2026-07-23 16:42:38 -05:00
1 parent d01dd31474
commit 682adca6bb
4 files changed
+80 -41

No files matched your search

@@ -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 (
<MapContainer
center={position}
zoom={16}
scrollWheelZoom
className={className}
attributionControl
>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker
position={position}
eventHandlers={{
mousedown: (event) => {
event.originalEvent.preventDefault();
event.originalEvent.stopPropagation();
},
}}
icon={markerIcon}
/>
</MapContainer>
);
}
@@ -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 <BrokenContent />;
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 (
<Box
@@ -752,28 +751,9 @@ export function MLocation({ content, showMaps }: MLocationProps) {
</Chip>
</Box>
{showMaps && isValid && (
<MapContainer
center={coords}
zoom={16}
scrollWheelZoom={true}
className={css.LocationMapContainer}
attributionControl
>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker
position={coords}
eventHandlers={{
mousedown: (e) => {
e.originalEvent.preventDefault();
e.originalEvent.stopPropagation();
},
}}
icon={markerIcon}
/>
</MapContainer>
<Suspense fallback={null}>
<LocationMap coordinates={coordinates} className={css.LocationMapContainer} />
</Suspense>
)}
</Box>
);
+23 -9
View File
@@ -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<HTMLDivElement, RoomInputProps>(
/>
)}
{showLocationPicker && (
<LocationDialog
onCancel={() => setShowLocationPicker(false)}
mx={mx}
room={room}
replyDraft={replyDraft}
clearReplyDraft={() => setReplyDraft(replyDraftBase)}
/>
<Suspense fallback={null}>
<LocationDialog
onCancel={() => setShowLocationPicker(false)}
mx={mx}
room={room}
replyDraft={replyDraft}
clearReplyDraft={() => setReplyDraft(replyDraftBase)}
/>
</Suspense>
)}
</div>
);
+3 -3
View File
@@ -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' },