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:
@@ -28,6 +28,7 @@ import {
|
||||
CREATE_PATH,
|
||||
} from './paths';
|
||||
import { trimLeadingSlash, trimTrailingSlash } from '../utils/common';
|
||||
import { tryDecodeURIComponent } from '../utils/dom';
|
||||
import { HashRouterConfig } from '../hooks/useClientConfig';
|
||||
import type { MatrixClient } from 'matrix-js-sdk';
|
||||
import { getCanonicalAliasOrRoomId } from '../utils/matrix';
|
||||
@@ -46,6 +47,18 @@ export const withSearchParam = <T extends Record<string, string>>(
|
||||
export const encodeSearchParamValueArray = (ids: string[]): string => ids.join(',');
|
||||
export const decodeSearchParamValueArray = (idsParam: string): string[] => idsParam.split(',');
|
||||
|
||||
/** Decode route params (React Router 7 encodes in generatePath — do not pre-encode). */
|
||||
export const decodeRouteParam = (param: string | undefined): string | undefined => {
|
||||
if (!param) return param;
|
||||
let decoded = param;
|
||||
let next = tryDecodeURIComponent(decoded);
|
||||
while (next !== decoded) {
|
||||
decoded = next;
|
||||
next = tryDecodeURIComponent(decoded);
|
||||
}
|
||||
return decoded;
|
||||
};
|
||||
|
||||
export const getOriginBaseUrl = (hashRouterConfig?: HashRouterConfig): string => {
|
||||
const baseUrl = `${trimTrailingSlash(window.location.origin)}${import.meta.env.BASE_URL}`;
|
||||
|
||||
@@ -79,17 +92,17 @@ export const getAppPathFromHref = (baseUrl: string, href: string): string => {
|
||||
export const getRootPath = (): string => ROOT_PATH;
|
||||
|
||||
export const getLoginPath = (server?: string): string => {
|
||||
const params = server ? { server: encodeURIComponent(server) } : undefined;
|
||||
const params = server ? { server } : undefined;
|
||||
return generatePath(LOGIN_PATH, params);
|
||||
};
|
||||
|
||||
export const getRegisterPath = (server?: string): string => {
|
||||
const params = server ? { server: encodeURIComponent(server) } : undefined;
|
||||
const params = server ? { server } : undefined;
|
||||
return generatePath(REGISTER_PATH, params);
|
||||
};
|
||||
|
||||
export const getResetPasswordPath = (server?: string): string => {
|
||||
const params = server ? { server: encodeURIComponent(server) } : undefined;
|
||||
const params = server ? { server } : undefined;
|
||||
return generatePath(RESET_PASSWORD_PATH, params);
|
||||
};
|
||||
|
||||
@@ -99,8 +112,8 @@ export const getHomeJoinPath = (): string => HOME_JOIN_PATH;
|
||||
export const getHomeSearchPath = (): string => HOME_SEARCH_PATH;
|
||||
export const getHomeRoomPath = (roomIdOrAlias: string, eventId?: string): string => {
|
||||
const params = {
|
||||
roomIdOrAlias: encodeURIComponent(roomIdOrAlias),
|
||||
eventId: eventId ? encodeURIComponent(eventId) : null,
|
||||
roomIdOrAlias,
|
||||
eventId: eventId ?? null,
|
||||
};
|
||||
|
||||
return generatePath(HOME_ROOM_PATH, params);
|
||||
@@ -110,8 +123,8 @@ export const getDirectPath = (): string => DIRECT_PATH;
|
||||
export const getDirectCreatePath = (): string => DIRECT_CREATE_PATH;
|
||||
export const getDirectRoomPath = (roomIdOrAlias: string, eventId?: string): string => {
|
||||
const params = {
|
||||
roomIdOrAlias: encodeURIComponent(roomIdOrAlias),
|
||||
eventId: eventId ? encodeURIComponent(eventId) : null,
|
||||
roomIdOrAlias,
|
||||
eventId: eventId ?? null,
|
||||
};
|
||||
|
||||
return generatePath(DIRECT_ROOM_PATH, params);
|
||||
@@ -121,20 +134,20 @@ export const getDirectInvitesPath = (): string => DIRECT_INVITES_PATH;
|
||||
|
||||
export const getSpacePath = (spaceIdOrAlias: string): string => {
|
||||
const params = {
|
||||
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias),
|
||||
spaceIdOrAlias,
|
||||
};
|
||||
|
||||
return generatePath(SPACE_PATH, params);
|
||||
};
|
||||
export const getSpaceLobbyPath = (spaceIdOrAlias: string): string => {
|
||||
const params = {
|
||||
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias),
|
||||
spaceIdOrAlias,
|
||||
};
|
||||
return generatePath(SPACE_LOBBY_PATH, params);
|
||||
};
|
||||
export const getSpaceFeedPath = (spaceIdOrAlias: string): string => {
|
||||
const params = {
|
||||
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias),
|
||||
spaceIdOrAlias,
|
||||
};
|
||||
return generatePath(SPACE_FEED_PATH, params);
|
||||
};
|
||||
@@ -149,7 +162,7 @@ export const getSpaceDefaultPath = (mx: MatrixClient, spaceId: string): string =
|
||||
};
|
||||
export const getSpaceSearchPath = (spaceIdOrAlias: string): string => {
|
||||
const params = {
|
||||
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias),
|
||||
spaceIdOrAlias,
|
||||
};
|
||||
return generatePath(SPACE_SEARCH_PATH, params);
|
||||
};
|
||||
@@ -159,9 +172,9 @@ export const getSpaceRoomPath = (
|
||||
eventId?: string
|
||||
): string => {
|
||||
const params = {
|
||||
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias),
|
||||
roomIdOrAlias: encodeURIComponent(roomIdOrAlias),
|
||||
eventId: eventId ? encodeURIComponent(eventId) : null,
|
||||
spaceIdOrAlias,
|
||||
roomIdOrAlias,
|
||||
eventId: eventId ?? null,
|
||||
};
|
||||
|
||||
return generatePath(SPACE_ROOM_PATH, params);
|
||||
@@ -171,7 +184,7 @@ export const getExplorePath = (): string => EXPLORE_PATH;
|
||||
export const getExploreFeaturedPath = (): string => EXPLORE_FEATURED_PATH;
|
||||
export const getExploreServerPath = (server: string): string => {
|
||||
const params = {
|
||||
server: encodeURIComponent(server),
|
||||
server,
|
||||
};
|
||||
return generatePath(EXPLORE_SERVER_PATH, params);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user