{
+ afterEach(() => {
+ localStorage.clear();
+ vi.unstubAllEnvs();
+ });
+
+ it('is disabled by default even in development', () => {
+ vi.stubEnv('VITE_ENABLE_REACT_QUERY_DEVTOOLS', 'false');
+
+ expect(isReactQueryDevtoolsEnabled()).toBe(false);
+ });
+
+ it('is enabled by the env variable', () => {
+ vi.stubEnv('VITE_ENABLE_REACT_QUERY_DEVTOOLS', 'true');
+
+ expect(isReactQueryDevtoolsEnabled()).toBe(true);
+ });
+
+ it('is enabled by the local storage flag', () => {
+ vi.stubEnv('VITE_ENABLE_REACT_QUERY_DEVTOOLS', 'false');
+ localStorage.setItem(REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY, '1');
+
+ expect(isReactQueryDevtoolsEnabled()).toBe(true);
+ });
+});
diff --git a/src/app/pages/reactQueryDevtoolsGate.ts b/src/app/pages/reactQueryDevtoolsGate.ts
new file mode 100644
index 00000000..aa77ba2e
--- /dev/null
+++ b/src/app/pages/reactQueryDevtoolsGate.ts
@@ -0,0 +1,5 @@
+export const REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY = 'sable_react_query_devtools';
+
+export const isReactQueryDevtoolsEnabled = (): boolean =>
+ import.meta.env.VITE_ENABLE_REACT_QUERY_DEVTOOLS === 'true' ||
+ localStorage.getItem(REACT_QUERY_DEVTOOLS_LOCAL_STORAGE_KEY) === '1';
diff --git a/src/app/plugins/react-custom-html-parser.test.tsx b/src/app/plugins/react-custom-html-parser.test.tsx
new file mode 100644
index 00000000..f1a66396
--- /dev/null
+++ b/src/app/plugins/react-custom-html-parser.test.tsx
@@ -0,0 +1,98 @@
+import { render, screen } from '@testing-library/react';
+import parse from 'html-react-parser';
+import { describe, expect, it } from 'vitest';
+import * as customHtmlCss from '$styles/CustomHtml.css';
+import {
+ LINKIFY_OPTS,
+ factoryRenderLinkifyWithMention,
+ getReactCustomHtmlParser,
+ makeMentionCustomProps,
+ renderMatrixMention,
+} from './react-custom-html-parser';
+
+const settingsLinkBaseUrl = 'https://app.example';
+
+const mockMx = {
+ getUserId: () => '@alice:example.org',
+ getRoom: () => undefined,
+};
+
+function Subject({ body }: { body: string }) {
+ const options = getReactCustomHtmlParser(mockMx as never, undefined, {
+ settingsLinkBaseUrl,
+ linkifyOpts: LINKIFY_OPTS,
+ handleMentionClick: undefined,
+ });
+
+ return {parse(body, options)}
;
+}
+
+describe('react custom html parser', () => {
+ it('renders same-origin raw settings permalinks as mention-style chips through the factory link render path', () => {
+ const renderLink = factoryRenderLinkifyWithMention(
+ settingsLinkBaseUrl,
+ () => undefined,
+ undefined
+ ) as (ir: never) => JSX.Element;
+
+ render(
+
+ {renderLink({
+ tagName: 'a',
+ attributes: {
+ href: 'https://app.example/settings/appearance/?focus=message-link-preview',
+ },
+ content: 'https://app.example/settings/appearance/?focus=message-link-preview',
+ } as never)}
+
+ );
+
+ const link = screen.getByRole('link', { name: 'Appearance / Message Link Preview' });
+ expect(link).toHaveAttribute('data-settings-link-section', 'appearance');
+ expect(link).toHaveAttribute('data-settings-link-focus', 'message-link-preview');
+ expect(link.className).toContain(customHtmlCss.Mention({}));
+ expect(link.className).toContain(customHtmlCss.SettingsMention);
+ expect(link).not.toHaveTextContent('Settings:');
+ });
+
+ it('renders same-origin settings permalinks as internal app links with settings metadata', () => {
+ render(
+
+ );
+
+ const link = screen.getByRole('link', { name: 'Appearance' });
+ expect(link).toHaveAttribute(
+ 'href',
+ 'https://app.example/settings/appearance/?focus=message-link-preview'
+ );
+ expect(link).toHaveAttribute('data-settings-link-section', 'appearance');
+ expect(link).toHaveAttribute('data-settings-link-focus', 'message-link-preview');
+ expect(link).not.toHaveAttribute('data-mention-id');
+ expect(link.className).toContain(customHtmlCss.Mention({}));
+ expect(link.className).toContain(customHtmlCss.SettingsMention);
+ });
+
+ it('renders matrix message permalinks with an icon instead of the Message prefix', () => {
+ render(
+
+ {renderMatrixMention(
+ {
+ getUserId: () => '@alice:example.org',
+ getRoom: () => ({ roomId: '!room:example.org', name: 'Lobby' }),
+ } as never,
+ undefined,
+ 'https://matrix.to/#/!room:example.org/$event123',
+ makeMentionCustomProps(undefined)
+ )}
+
+ );
+
+ const link = screen.getByRole('link', { name: '#Lobby' });
+ expect(link).toHaveAttribute('data-mention-id', '!room:example.org');
+ expect(link).toHaveAttribute('data-mention-event-id', '$event123');
+ expect(link.className).toContain(customHtmlCss.Mention({}));
+ expect(link.className).toContain(customHtmlCss.SettingsMention);
+ expect(link).not.toHaveTextContent('Message:');
+ expect(link.querySelector('[aria-hidden="true"]')).not.toBeNull();
+ });
+});
diff --git a/src/app/plugins/react-custom-html-parser.tsx b/src/app/plugins/react-custom-html-parser.tsx
index 1a351572..efb8991b 100644
--- a/src/app/plugins/react-custom-html-parser.tsx
+++ b/src/app/plugins/react-custom-html-parser.tsx
@@ -36,6 +36,8 @@ import { findAndReplace } from '$utils/findAndReplace';
import { onEnterOrSpace } from '$utils/keyboard';
import { copyToClipboard } from '$utils/dom';
import { useTimeoutToggle } from '$hooks/useTimeoutToggle';
+import { parseSettingsPermalink } from '$features/settings/settingsLink';
+import { settingsSections } from '$features/settings/routes';
import { ClientSideHoverFreeze } from '$components/ClientSideHoverFreeze';
import {
parseMatrixToRoom,
@@ -138,21 +140,26 @@ export const renderMatrixMention = (
const mentionRoom = mx.getRoom(
isRoomAlias(roomIdOrAlias) ? getCanonicalAliasRoomId(mx, roomIdOrAlias) : roomIdOrAlias
);
+ const fallbackContent = mentionRoom ? `#${mentionRoom.name}` : roomIdOrAlias;
return (
- {customProps.children
- ? customProps.children
- : `Message: ${mentionRoom ? `#${mentionRoom.name}` : roomIdOrAlias}`}
+
+
+
+ {customProps.children ? customProps.children : fallbackContent}
);
}
@@ -160,8 +167,80 @@ export const renderMatrixMention = (
return undefined;
};
+const settingsSectionLabel = Object.fromEntries(
+ settingsSections.map((section) => [section.id, section.label])
+) as Record<(typeof settingsSections)[number]['id'], string>;
+
+const humanizeSettingsPermalinkPart = (value: string): string =>
+ value
+ .split(/[^a-zA-Z0-9]+/)
+ .filter(Boolean)
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
+ .join(' ');
+
+const getSettingsPermalinkLabel = (
+ section: keyof typeof settingsSectionLabel,
+ focus?: string
+): string => {
+ const sectionLabel = settingsSectionLabel[section];
+ const focusLabel = focus ? humanizeSettingsPermalinkPart(focus) : undefined;
+
+ return focusLabel ? `${sectionLabel} / ${focusLabel}` : sectionLabel;
+};
+
+const getSettingsPermalinkChildren = ({
+ href,
+ section,
+ focus,
+ content,
+ fallbackChildren,
+}: {
+ href: string;
+ section: keyof typeof settingsSectionLabel;
+ focus?: string;
+ content?: string;
+ fallbackChildren?: ReactNode;
+}): ReactNode => {
+ if (!content || content === href || content === safeDecodeUrl(href)) {
+ return getSettingsPermalinkLabel(section, focus);
+ }
+
+ return fallbackChildren ?? content;
+};
+
+const renderSettingsPermalink = ({
+ href,
+ section,
+ focus,
+ handleMentionClick,
+ content,
+ fallbackChildren,
+}: {
+ href: string;
+ section: keyof typeof settingsSectionLabel;
+ focus?: string;
+ handleMentionClick?: ReactEventHandler;
+ content?: string;
+ fallbackChildren?: ReactNode;
+}) => (
+
+
+
+
+ {getSettingsPermalinkChildren({ href, section, focus, content, fallbackChildren })}
+
+);
+
export const factoryRenderLinkifyWithMention = (
- mentionRender: (href: string) => JSX.Element | undefined
+ settingsLinkBaseUrl: string,
+ mentionRender: (href: string) => JSX.Element | undefined,
+ handleMentionClick?: ReactEventHandler
): OptFn<(ir: IntermediateRepresentation) => any> => {
const renderLink: OptFn<(ir: IntermediateRepresentation) => any> = ({
tagName,
@@ -176,6 +255,21 @@ export const factoryRenderLinkifyWithMention = (
if (mention) return mention;
}
+ if (tagName === 'a' && decodedHref) {
+ const settingsPermalink = parseSettingsPermalink(settingsLinkBaseUrl, decodedHref);
+ if (settingsPermalink) {
+ const { section, focus } = settingsPermalink;
+ return renderSettingsPermalink({
+ href: decodedHref,
+ section,
+ focus,
+ handleMentionClick,
+ content,
+ fallbackChildren: content,
+ });
+ }
+ }
+
return {content};
};
@@ -344,6 +438,7 @@ export const getReactCustomHtmlParser = (
mx: MatrixClient,
roomId: string | undefined,
params: {
+ settingsLinkBaseUrl: string;
linkifyOpts: LinkifyOpts;
highlightRegex?: RegExp;
handleSpoilerClick?: ReactEventHandler;
@@ -489,23 +584,41 @@ export const getReactCustomHtmlParser = (
if (name === 'a' && typeof props.href === 'string') {
const encodedHref = props.href;
const decodedHref = encodedHref && safeDecodeUrl(encodedHref);
- if (!decodedHref || !testMatrixTo(decodedHref)) {
- return undefined;
- }
+ const renderedChildren = renderChildren();
const content = children.find((child) => !(child instanceof DOMText))
? undefined
: children.map((c) => (c instanceof DOMText ? c.data : '')).join();
- const mention = renderMatrixMention(
- mx,
- roomId,
- safeDecodeUrl(props.href),
- makeMentionCustomProps(params.handleMentionClick, content),
- params.nicknames
- );
+ if (decodedHref && testMatrixTo(decodedHref)) {
+ const mention = renderMatrixMention(
+ mx,
+ roomId,
+ decodedHref,
+ makeMentionCustomProps(params.handleMentionClick, content),
+ params.nicknames
+ );
- if (mention) return mention;
+ if (mention) return mention;
+ }
+
+ if (decodedHref) {
+ const settingsPermalink = parseSettingsPermalink(
+ params.settingsLinkBaseUrl,
+ decodedHref
+ );
+ if (settingsPermalink) {
+ const { section, focus } = settingsPermalink;
+ return renderSettingsPermalink({
+ href: decodedHref,
+ section,
+ focus,
+ handleMentionClick: params.handleMentionClick,
+ content,
+ fallbackChildren: renderedChildren,
+ });
+ }
+ }
}
if (name === 'span' && 'data-mx-spoiler' in props) {
diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts
index cfa53386..0b4bf15d 100644
--- a/src/app/state/settings.ts
+++ b/src/app/state/settings.ts
@@ -69,6 +69,7 @@ export interface Settings {
developerTools: boolean;
enableMSC4268CMD: boolean;
settingsSyncEnabled: boolean;
+ settingsLinkBaseUrlOverride?: string;
// Cosmetics!
jumboEmojiSize: JumboEmojiSize;
@@ -162,6 +163,7 @@ const defaultSettings: Settings = {
developerTools: false,
settingsSyncEnabled: false,
+ settingsLinkBaseUrlOverride: undefined,
// Cosmetics!
jumboEmojiSize: 'normal',
diff --git a/src/app/styles/CustomHtml.css.ts b/src/app/styles/CustomHtml.css.ts
index 6ff53d9d..2102ea4e 100644
--- a/src/app/styles/CustomHtml.css.ts
+++ b/src/app/styles/CustomHtml.css.ts
@@ -171,6 +171,18 @@ export const Mention = recipe({
},
});
+export const SettingsMention = style({
+ display: 'inline-flex',
+ alignItems: 'center',
+ gap: config.space.S100,
+ padding: `0 ${config.space.S100}`,
+});
+
+export const SettingsMentionIcon = style({
+ display: 'inline-flex',
+ flexShrink: 0,
+});
+
export const Command = recipe({
base: [
DefaultReset,
diff --git a/src/app/utils/dom.ts b/src/app/utils/dom.ts
index 12fc93e7..e51bdfed 100644
--- a/src/app/utils/dom.ts
+++ b/src/app/utils/dom.ts
@@ -187,22 +187,35 @@ export const scrollToBottom = (scrollEl: HTMLElement, behavior?: 'auto' | 'insta
});
};
-export const copyToClipboard = (text: string) => {
+export const copyToClipboard = async (text: string): Promise => {
if (navigator.clipboard) {
- navigator.clipboard.writeText(text);
- } else {
- const host = document.body;
- const copyInput = document.createElement('input');
- copyInput.style.position = 'fixed';
- copyInput.style.opacity = '0';
- copyInput.value = text;
- host.append(copyInput);
-
- copyInput.select();
- copyInput.setSelectionRange(0, 99999);
- document.execCommand('Copy');
- copyInput.remove();
+ try {
+ await navigator.clipboard.writeText(text);
+ return true;
+ } catch {
+ return false;
+ }
}
+
+ const host = document.body;
+ const copyInput = document.createElement('input');
+ copyInput.style.position = 'fixed';
+ copyInput.style.opacity = '0';
+ copyInput.value = text;
+ host.append(copyInput);
+
+ copyInput.select();
+ copyInput.setSelectionRange(0, 99999);
+
+ let copied = false;
+ try {
+ copied = document.execCommand('Copy');
+ } catch {
+ copied = false;
+ }
+
+ copyInput.remove();
+ return copied;
};
export const setFavicon = (url: string): void => {
diff --git a/src/app/utils/settingsSync.test.ts b/src/app/utils/settingsSync.test.ts
index 66c4f527..fb5ad6c8 100644
--- a/src/app/utils/settingsSync.test.ts
+++ b/src/app/utils/settingsSync.test.ts
@@ -30,6 +30,7 @@ describe('NON_SYNCABLE_KEYS', () => {
'isPeopleDrawer',
'isWidgetDrawer',
'memberSortFilterIndex',
+ 'settingsLinkBaseUrlOverride',
'developerTools',
'settingsSyncEnabled',
] as const;
diff --git a/src/app/utils/settingsSync.ts b/src/app/utils/settingsSync.ts
index a154ff92..0f6b2588 100644
--- a/src/app/utils/settingsSync.ts
+++ b/src/app/utils/settingsSync.ts
@@ -14,6 +14,7 @@ export const NON_SYNCABLE_KEYS = new Set([
'isPeopleDrawer',
'isWidgetDrawer',
'memberSortFilterIndex',
+ 'settingsLinkBaseUrlOverride',
// Developer / diagnostic
'developerTools',
// Sync toggle itself must never be uploaded (it's device-local)