From 22519b57a0a971ab927a03015c994c63b8c3f1da Mon Sep 17 00:00:00 2001 From: memoclaw <265580040+memoclaw@users.noreply.github.com> Date: Mon, 23 Mar 2026 20:34:14 +0800 Subject: [PATCH] fix(web): prevent MemoContent prop leaks --- web/src/components/MemoContent/Tag.tsx | 4 +- web/src/components/MemoContent/index.tsx | 57 +++++++++++++++++------- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/web/src/components/MemoContent/Tag.tsx b/web/src/components/MemoContent/Tag.tsx index 7b65ba2e..361a1ec4 100644 --- a/web/src/components/MemoContent/Tag.tsx +++ b/web/src/components/MemoContent/Tag.tsx @@ -15,7 +15,7 @@ interface TagProps extends React.HTMLAttributes { children?: React.ReactNode; } -export const Tag: React.FC = ({ "data-tag": dataTag, children, className, style, ...props }) => { +export const Tag: React.FC = ({ "data-tag": dataTag, children, className, style, node: _node, ...props }) => { const { parentPage } = useMemoViewContext(); const location = useLocation(); const navigateTo = useNavigateTo(); @@ -66,7 +66,7 @@ export const Tag: React.FC = ({ "data-tag": dataTag, children, classNa return ( { components={{ // Child components consume from MemoViewContext directly input: ((inputProps: React.ComponentProps<"input"> & { node?: Element }) => { - if (inputProps.node && isTaskListItemNode(inputProps.node)) { + const { node, ...rest } = inputProps; + if (node && isTaskListItemNode(node)) { return ; } - return ; + return ; }) as React.ComponentType>, span: ((spanProps: React.ComponentProps<"span"> & { node?: Element }) => { const { node, ...rest } = spanProps; @@ -68,16 +69,40 @@ const MemoContent = (props: MemoContentProps) => { return ; }) as React.ComponentType>, // Headings - h1: ({ children }) => {children}, - h2: ({ children }) => {children}, - h3: ({ children }) => {children}, - h4: ({ children }) => {children}, - h5: ({ children }) => {children}, - h6: ({ children }) => {children}, + h1: ({ children, ...props }) => ( + + {children} + + ), + h2: ({ children, ...props }) => ( + + {children} + + ), + h3: ({ children, ...props }) => ( + + {children} + + ), + h4: ({ children, ...props }) => ( + + {children} + + ), + h5: ({ children, ...props }) => ( + + {children} + + ), + h6: ({ children, ...props }) => ( + + {children} + + ), // Block elements - p: ({ children }) => {children}, - blockquote: ({ children }) =>
{children}
, - hr: () => , + p: ({ children, ...props }) => {children}, + blockquote: ({ children, ...props }) =>
{children}
, + hr: (props) => , // Lists ul: ({ children, ...props }) => {children}, ol: ({ children, ...props }) => ( @@ -88,15 +113,15 @@ const MemoContent = (props: MemoContentProps) => { li: ({ children, ...props }) => {children}, // Inline elements a: ({ children, ...props }) => {children}, - code: ({ children }) => {children}, + code: ({ children, ...props }) => {children}, img: ({ ...props }) => , // Code blocks pre: CodeBlock, // Tables - table: ({ children }) => {children}
, - thead: ({ children }) => {children}, - tbody: ({ children }) => {children}, - tr: ({ children }) => {children}, + table: ({ children, ...props }) => {children}
, + thead: ({ children, ...props }) => {children}, + tbody: ({ children, ...props }) => {children}, + tr: ({ children, ...props }) => {children}, th: ({ children, ...props }) => {children}, td: ({ children, ...props }) => {children}, }}