Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Empty images around equations render as question marks on Safari… #7019

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/lexical-playground/src/ui/KatexRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import katex from 'katex';
import * as React from 'react';
import {useEffect, useRef} from 'react';
import {useEffect, useRef, useState} from 'react';

export default function KatexRenderer({
equation,
Expand All @@ -20,13 +20,20 @@ export default function KatexRenderer({
onDoubleClick: () => void;
}>): JSX.Element {
const katexElementRef = useRef(null);
const [isSafari, setIsSafari] = useState(false); // State to track if the browser is Safari

// Detect if the browser is Safari during the client rendering phase
useEffect(() => {
const userAgent = navigator.userAgent;
setIsSafari(/^((?!chrome|android).)*safari/i.test(userAgent));
}, []);

useEffect(() => {
const katexElement = katexElementRef.current;

if (katexElement !== null) {
katex.render(equation, katexElement, {
displayMode: !inline, // true === block display //
displayMode: !inline, // true === block display
errorColor: '#cc0000',
output: 'html',
strict: 'warn',
Expand All @@ -37,6 +44,7 @@ export default function KatexRenderer({
}, [equation, inline]);

return (
// Use empty image tags conditionally based on the browser
// We use an empty image tag either side to ensure Android doesn't try and compose from the
// inner text from Katex. There didn't seem to be any other way of making this work,
// without having a physical space.
Expand All @@ -48,7 +56,7 @@ export default function KatexRenderer({
onDoubleClick={onDoubleClick}
ref={katexElementRef}
/>
<img src="#" alt="" />
{!isSafari && <img src="#" alt="" />}
</>
);
}
Loading