fix(privacy): hide currency symbols in redacted overlay (#6438)

* fix(privacy): hide currency symbols in redacted overlay

Add RedactedContent component that uses useLayoutEffect to walk the DOM
and replace non-alphanumeric characters (like currency symbols) with spaces.
This ensures characters not rendered by Redacted Script font are hidden,
regardless of how deeply nested they are in the component tree.

* refactor: simplify RedactedContent text node processing loop
This commit is contained in:
Stephen Brown II
2026-01-13 17:19:19 -05:00
committed by GitHub
parent b88feb9336
commit 93cce07542
2 changed files with 40 additions and 2 deletions

View File

@@ -1,8 +1,10 @@
// @ts-strict-ignore
import React, {
import {
Children,
type ComponentPropsWithRef,
type ReactNode,
useLayoutEffect,
useRef,
} from 'react';
import { useResponsive } from '@actual-app/components/hooks/useResponsive';
@@ -67,6 +69,36 @@ export function PrivacyFilter({
);
}
type RedactedContentProps = {
children: ReactNode;
};
// Component that filters text content to remove non-alphanumeric characters
// This works by intercepting the actual rendered text via a ref and modifying it
function RedactedContent({ children }: RedactedContentProps) {
const containerRef = useRef<HTMLDivElement>(null);
useLayoutEffect(() => {
if (containerRef.current) {
// Walk all text nodes and replace non-alphanumeric characters
const walker = document.createTreeWalker(
containerRef.current,
NodeFilter.SHOW_TEXT,
null,
);
let node: Text | null;
while ((node = walker.nextNode() as Text | null)) {
if (node.textContent) {
node.textContent = node.textContent.replace(/[^a-zA-Z0-9]/g, '*');
}
}
}
}, [children]);
return <div ref={containerRef}>{children}</div>;
}
function PrivacyOverlay({ children, ...props }) {
const { style, ...restProps } = props;
@@ -122,7 +154,7 @@ function PrivacyOverlay({ children, ...props }) {
width: '100%',
})}
>
{children}
<RedactedContent>{children}</RedactedContent>
</div>
</View>
);

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [StephenBrown2]
---
Fixes redacted content to work with currency symbols