diff --git a/apps/renderer/src/components/common/ShadowDOM.tsx b/apps/renderer/src/components/common/ShadowDOM.tsx index f709892439..e57c3d62c1 100644 --- a/apps/renderer/src/components/common/ShadowDOM.tsx +++ b/apps/renderer/src/components/common/ShadowDOM.tsx @@ -53,14 +53,21 @@ const cloneStylesElement = (_mutationRecord?: MutationRecord) => { return reactNodes } -export const ShadowDOM: FC>> & { +export const ShadowDOM: FC< + PropsWithChildren> & { + injectHostStyles?: boolean + } +> & { useIsShadowDOM: () => boolean } = (props) => { - const { ...rest } = props + const { injectHostStyles = true, ...rest } = props - const [stylesElements, setStylesElements] = useState(cloneStylesElement) + const [stylesElements, setStylesElements] = useState(() => + injectHostStyles ? cloneStylesElement() : [], + ) useLayoutEffect(() => { + if (!injectHostStyles) return const mutationObserver = new MutationObserver((e) => { const event = e[0] @@ -74,7 +81,7 @@ export const ShadowDOM: FC>> & { return () => { mutationObserver.disconnect() } - }, []) + }, [injectHostStyles]) const dark = useIsDark() @@ -98,7 +105,7 @@ export const ShadowDOM: FC>> & { data-theme={dark ? "dark" : "light"} className="font-theme" > - {stylesElements} + {injectHostStyles ? stylesElements : null} {props.children} diff --git a/apps/renderer/src/lib/parse-html.ts b/apps/renderer/src/lib/parse-html.ts index 6f30118ff3..7474599e9b 100644 --- a/apps/renderer/src/lib/parse-html.ts +++ b/apps/renderer/src/lib/parse-html.ts @@ -15,6 +15,7 @@ import type { Node } from "unist" import { visit } from "unist-util-visit" import { VFile } from "vfile" +import { MemoedDangerousHTMLStyle } from "~/components/common/MemoedDangerousHTMLStyle" import { ShadowDOM } from "~/components/common/ShadowDOM" import { Checkbox } from "~/components/ui/checkbox" import { ShikiHighLighter } from "~/components/ui/code-highlighter" @@ -312,10 +313,12 @@ export function extractCodeFromHtml(htmlString: string) { const Style: Components["style"] = ({ node, ...props }) => { const isShadowDOM = ShadowDOM.useIsShadowDOM() - if (isShadowDOM) { - return createElement("style", { - ...props, - }) + if (isShadowDOM && typeof props.children === "string") { + return createElement( + MemoedDangerousHTMLStyle, + null, + props.children.replaceAll(/html|body/g, "#shadow-html"), + ) } return null } diff --git a/apps/renderer/src/modules/entry-content/index.tsx b/apps/renderer/src/modules/entry-content/index.tsx index 34a4687834..1186378b2a 100644 --- a/apps/renderer/src/modules/entry-content/index.tsx +++ b/apps/renderer/src/modules/entry-content/index.tsx @@ -215,6 +215,8 @@ export const EntryContentRender: Component<{ }) } + const isInbox = feed?.type === "inbox" + return ( <> {!isInReadabilityMode ? ( - + {isPending ? ( - + ) : error ? (