7b01cfebf5
- nginx (LXC 106, live): added https://*.giphy.com to connect-src CSP — browser was blocking fetch() to media2.giphy.com CDN with CSP violation - EditHistoryModal: render formatted_body as sanitized HTML (via html-react-parser + sanitizeCustomHtml) with linkification for plain text, matching how messages render in the timeline - useAsyncCallback + ThumbnailContent + ImageContent + VideoContent + ClientConfigLoader: use .catch(() => undefined) instead of void to silence unhandled promise rejections from fire-and-forget useEffect calls — errors already captured in AsyncState.Error for UI display Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { ReactNode, useCallback, useEffect, useState } from 'react';
|
|
import { AsyncStatus, useAsyncCallback } from '../hooks/useAsyncCallback';
|
|
import { ClientConfig } from '../hooks/useClientConfig';
|
|
import { trimTrailingSlash } from '../utils/common';
|
|
|
|
const getClientConfig = async (): Promise<ClientConfig> => {
|
|
const url = `${trimTrailingSlash(import.meta.env.BASE_URL)}/config.json`;
|
|
const config = await fetch(url, { method: 'GET' });
|
|
return config.json();
|
|
};
|
|
|
|
type ClientConfigLoaderProps = {
|
|
fallback?: () => ReactNode;
|
|
error?: (err: unknown, retry: () => void, ignore: () => void) => ReactNode;
|
|
children: (config: ClientConfig) => ReactNode;
|
|
};
|
|
export function ClientConfigLoader({ fallback, error, children }: ClientConfigLoaderProps) {
|
|
const [state, load] = useAsyncCallback(getClientConfig);
|
|
const [ignoreError, setIgnoreError] = useState(false);
|
|
|
|
const ignoreCallback = useCallback(() => setIgnoreError(true), []);
|
|
|
|
useEffect(() => {
|
|
load().catch(() => undefined);
|
|
}, [load]);
|
|
|
|
if (state.status === AsyncStatus.Idle || state.status === AsyncStatus.Loading) {
|
|
return fallback?.();
|
|
}
|
|
|
|
if (!ignoreError && state.status === AsyncStatus.Error) {
|
|
return error?.(state.error, load, ignoreCallback);
|
|
}
|
|
|
|
const config: ClientConfig = state.status === AsyncStatus.Success ? state.data : {};
|
|
|
|
return children(config);
|
|
}
|