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

Conversation

Codebreaker42
Copy link

@Codebreaker42 Codebreaker42 commented Jan 7, 2025

[lexical-playground] Bug Fix: Remove empty images around equations causing question marks in Safari (#6824)

Description

Current Behavior

Equations rendered using the KatexRenderer component include empty <img> tags as placeholders, which appear as question marks in Safari due to Safari’s handling of empty images.

Changes Made

  • Removed empty <img> tags around the equation rendering in KatexRenderer component.
  • Modified the comment to explain the new workaround.
  • Verified that Android-specific composition issues with equations remain unaffected.

Closes #6824
Closes #6836

Test plan

Before

In Safari:

  • Equations show up with question marks around them.
  • Example: a+b=c

Rendered incorrectly due to <img> placeholders.

Screenshots/recordings showing the issue:

!Before Screenshot {8D587512-54D7-41BB-838E-C6C9AFB9AF53}

After

In Safari:

  • Equations are rendered correctly without question marks.
  • The issue with Android composition remains resolved even after removing the empty <img> tags.

Screenshots/recordings showing the fix:

!After Screenshot {AE51DBD3-074B-405F-8883-DB51D1F7E025}

Copy link

vercel bot commented Jan 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 4:16am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 7, 2025 4:16am

@facebook-github-bot
Copy link
Contributor

Hi @Codebreaker42!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link

github-actions bot commented Jan 7, 2025

size-limit report 📦

Path Size
lexical - cjs 31.39 KB (0%)
lexical - esm 31.19 KB (0%)
@lexical/rich-text - cjs 40.47 KB (0%)
@lexical/rich-text - esm 33.12 KB (0%)
@lexical/plain-text - cjs 39.04 KB (0%)
@lexical/plain-text - esm 30.37 KB (0%)
@lexical/react - cjs 42.3 KB (0%)
@lexical/react - esm 34.42 KB (0%)

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 7, 2025
Comment on lines 40 to 46
// 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.
<>
<img src="#" alt="" />
{/* Add empty <img> tags only if the browser is not Safari */}
{!isSafari && <img src="#" alt="" />}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to leave some comments about why the img tags are there in the first place, otherwise this looks like a reasonable enough approach

@@ -21,12 +22,15 @@ export default function KatexRenderer({
}>): JSX.Element {
const katexElementRef = useRef(null);

// Detect if the browser is Safari
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may cause some issues with SSR, so it might be better to do this with state and a layout effect or something like that, although I'm not sure if this component is compatible with SSR in the first place. Risk is fairly low since this is not a published component.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback! You're absolutely right that directly using navigator.userAgent in the component could cause issues with SSR. I've updated the implementation to detect if the browser is Safari using a useEffect hook and state. This ensures the detection logic runs only on the client side, mitigating potential SSR issues.

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

It looks like integrity checks are failing, you can run these locally with npm run ci-check. In this case I think it's a formatting issue that can be fixed with npm run prettier:fix

@Codebreaker42
Copy link
Author

It looks like integrity checks are failing, you can run these locally with npm run ci-check. In this case I think it's a formatting issue that can be fixed with npm run prettier:fix

Thank you for pointing that out! I'll run the integrity checks locally using npm run ci-check to identify the issue. If it's a formatting issue, I'll fix it using npm run prettier:fix as suggested.

I'll update the pull request once everything passes. Thanks again for the guidance!

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version doesn't work for me with Safari 18.2 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15)
Screenshot 2025-01-06 at 22 23 09

@etrepum
Copy link
Collaborator

etrepum commented Jan 7, 2025

This was tested in the preview app from the latest commit https://lexical-playground-9mxzhz6fh-fbopensource.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: empty images around equations render as question marks on Safari
3 participants