fix: restore rooms and DMs after React Router 7 upgrade
Stop double-encoding Matrix IDs in pathUtils, decode route params on read, fix millify CJS import, and read space children from currentState so channels and joins work again.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { decodeRouteParam } from '../../pathUtils';
|
||||
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
||||
import { IsDirectRoomProvider, RoomProvider } from '../../../hooks/useRoom';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
@@ -10,12 +11,19 @@ export function DirectRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const mx = useMatrixClient();
|
||||
const rooms = useDirectRooms();
|
||||
|
||||
const { roomIdOrAlias, eventId } = useParams();
|
||||
const { roomIdOrAlias: rawRoomIdOrAlias, eventId: rawEventId } = useParams();
|
||||
const roomIdOrAlias = decodeRouteParam(rawRoomIdOrAlias);
|
||||
const eventId = decodeRouteParam(rawEventId);
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
if (!room || !rooms.includes(room.roomId)) {
|
||||
return <JoinBeforeNavigate roomIdOrAlias={roomIdOrAlias!} eventId={eventId} />;
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={roomIdOrAlias ?? rawRoomIdOrAlias!}
|
||||
eventId={eventId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -20,7 +20,7 @@ import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { RoomTopicViewer } from '../../../components/room-topic-viewer';
|
||||
import { RoomCard, RoomCardBase, RoomCardGrid } from '../../../components/room-card';
|
||||
import { ExploreServerPathSearchParams } from '../../paths';
|
||||
import { getExploreServerPath, withSearchParam } from '../../pathUtils';
|
||||
import { getExploreServerPath, decodeRouteParam, withSearchParam } from '../../pathUtils';
|
||||
import * as css from './style.css';
|
||||
import { allRoomsAtom } from '../../../state/room-list/roomList';
|
||||
import { useRoomNavigate } from '../../../hooks/useRoomNavigate';
|
||||
@@ -324,7 +324,8 @@ function LimitButton({ limit, onLimitChange }: LimitButtonProps) {
|
||||
}
|
||||
|
||||
export function PublicRooms() {
|
||||
const { server } = useParams();
|
||||
const { server: rawServer } = useParams();
|
||||
const server = decodeRouteParam(rawServer);
|
||||
const mx = useMatrixClient();
|
||||
const userId = mx.getUserId();
|
||||
const userServer = userId && getMxIdServer(userId);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { decodeRouteParam } from '../../pathUtils';
|
||||
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
||||
import { IsDirectRoomProvider, RoomProvider } from '../../../hooks/useRoom';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
@@ -11,7 +12,9 @@ export function HomeRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const mx = useMatrixClient();
|
||||
const rooms = useHomeRooms();
|
||||
|
||||
const { roomIdOrAlias, eventId } = useParams();
|
||||
const { roomIdOrAlias: rawRoomIdOrAlias, eventId: rawEventId } = useParams();
|
||||
const roomIdOrAlias = decodeRouteParam(rawRoomIdOrAlias);
|
||||
const eventId = decodeRouteParam(rawEventId);
|
||||
const viaServers = useSearchParamsViaServers();
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
@@ -19,7 +22,7 @@ export function HomeRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
if (!room || !rooms.includes(room.roomId)) {
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={roomIdOrAlias!}
|
||||
roomIdOrAlias={roomIdOrAlias ?? rawRoomIdOrAlias!}
|
||||
eventId={eventId}
|
||||
viaServers={viaServers}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { decodeRouteParam } from '../../pathUtils';
|
||||
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
||||
import { IsDirectRoomProvider, RoomProvider } from '../../../hooks/useRoom';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
@@ -22,7 +23,9 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
const allRooms = useAtomValue(allRoomsAtom);
|
||||
|
||||
const { roomIdOrAlias, eventId } = useParams();
|
||||
const { roomIdOrAlias: rawRoomIdOrAlias, eventId: rawEventId } = useParams();
|
||||
const roomIdOrAlias = decodeRouteParam(rawRoomIdOrAlias);
|
||||
const eventId = decodeRouteParam(rawEventId);
|
||||
const viaServers = useSearchParamsViaServers();
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
@@ -31,7 +34,7 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
// room is not joined
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={roomIdOrAlias!}
|
||||
roomIdOrAlias={roomIdOrAlias ?? rawRoomIdOrAlias!}
|
||||
eventId={eventId}
|
||||
viaServers={viaServers}
|
||||
/>
|
||||
@@ -59,7 +62,7 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={roomIdOrAlias!}
|
||||
roomIdOrAlias={roomIdOrAlias ?? rawRoomIdOrAlias!}
|
||||
eventId={eventId}
|
||||
viaServers={viaServers}
|
||||
/>
|
||||
|
||||
@@ -324,7 +324,7 @@ export function Space() {
|
||||
const virtualizer = useVirtualizer({
|
||||
count: flattenedHierarchy.length,
|
||||
getScrollElement: () => scrollRef.current,
|
||||
estimateSize: () => 0,
|
||||
estimateSize: () => 32,
|
||||
overscan: 10,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { ReactNode } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { decodeRouteParam } from '../../pathUtils';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { useAutoJoinOnSpaceVisit } from '../../../hooks/useAutoJoinSpaceRooms';
|
||||
import { useSpaces } from '../../../state/hooks/roomList';
|
||||
@@ -16,7 +17,8 @@ export function RouteSpaceProvider({ children }: RouteSpaceProviderProps) {
|
||||
const mx = useMatrixClient();
|
||||
const joinedSpaces = useSpaces(mx, allRoomsAtom);
|
||||
|
||||
const { spaceIdOrAlias } = useParams();
|
||||
const { spaceIdOrAlias: rawSpaceIdOrAlias } = useParams();
|
||||
const spaceIdOrAlias = decodeRouteParam(rawSpaceIdOrAlias);
|
||||
const viaServers = useSearchParamsViaServers();
|
||||
|
||||
const selectedSpaceId = useSelectedSpace();
|
||||
@@ -25,7 +27,12 @@ export function RouteSpaceProvider({ children }: RouteSpaceProviderProps) {
|
||||
useAutoJoinOnSpaceVisit(space ?? undefined);
|
||||
|
||||
if (!space || !joinedSpaces.includes(space.roomId)) {
|
||||
return <JoinBeforeNavigate roomIdOrAlias={spaceIdOrAlias ?? ''} viaServers={viaServers} />;
|
||||
return (
|
||||
<JoinBeforeNavigate
|
||||
roomIdOrAlias={spaceIdOrAlias ?? rawSpaceIdOrAlias ?? ''}
|
||||
viaServers={viaServers}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user