from Hacker News

Lexical – a web text editor framework that powers Facebook

by trueadm on 6/20/22, 6:08 PM with 105 comments

  • by trueadm on 6/20/22, 6:23 PM

    I'm the author of Lexical and one of the many engineers working on Lexical full-time at Meta. If you'd like to know anything, or ask any questions, please do!

    For those of you looking for the sourcecode for the playground, you can find it here:

    https://github.com/facebook/lexical/tree/main/packages/lexic...

    We also have a Discord channel you can check out:

    https://discord.gg/KmG4wQnnD9

  • by euroderf on 6/21/22, 6:43 AM

    Is it a LOT to ask? => Could the docs PLEASE link to a downloadable runnable self-contained HTML page containing one or two editor instances in Vanilla JS? Same ask for ProseMirror.

    Maybe such a page would pull the JS from a CDN, maybe it would refer to filepaths on the server.

    I don't know how to form a working web page from the snippets in the docu because I do not know the relevant javascript. I would just like a working example, on my own computer, with a minimum number of moving parts, that I can play around with.

  • by jitl on 6/20/22, 6:48 PM

    How do you handle Android and multi-lingual input? Writing the state machine to deal with Chrome/Android’s bananas selection bugs in Notion’s editor gave me a lot of headaches. Do you add extra DOM nodes on Android? Any key insights that help deal with IME on Android?
  • by lawrencechen on 6/21/22, 6:54 AM

    I put Lexical through Hog Bay's Moby Dick test [0] (paste the entirety of Moby Dick, scroll to the middle, and try editing). It didn't pass. AFAIK, only ProseMirror passes, albeit with some lag.

    [0] https://www.hogbaysoftware.com/posts/moby-dick-workout/

  • by barbinbrad on 6/20/22, 7:56 PM

    We're trying to choose between Lexical and Slate at work. Do you have any code examples that would be similar to this?

    Example: https://www.slatejs.org/examples/richtext

    Code: https://github.com/ianstormtaylor/slate/blob/main/site/examp...

  • by saimiam on 6/21/22, 5:54 AM

    A few days ago, I was looking to create an editable interface for an email composer for a project I’m working on (https://PretzelBox.cc, since you asked).

    I wanted to see if Lexical was a good fit. My app is plain javascript with a bit of Alpine and htmx. I just couldn’t figure out how to <link> to the appropriate js file in my html file. And I’m not a frontend dev so I have no idea how to browserify (or whatever the technical term is) the right npm modules.

    I ended up using MediumEditor which is ancient in relative terms. Anyway, now composing email feels like writing a Medium post, fwiw.

  • by pxeger1 on 6/20/22, 7:43 PM

    In what sense does this "power" Facebook? Do you mean it's used for most or some specific text editing components of Facebook?
  • by laqq3 on 6/21/22, 4:18 AM

    This looks great!

    Curious whether the team is looking at improving the support of having images in tables cell? I played with the playground and it seems to work, but there seems to be some (relatively minor) glitches/bugs (e.g. difficult to place an image in a cell, moving images across cells seems difficult, and cannot Ctrl-x an image and Ctrl-v to paste it).

  • by latchkey on 6/20/22, 9:49 PM

    It is interesting (and cool) that this uses Typescript over Flow. It seems like Flow is still being developed too.

    Just looking at the top level package.json [1], I wonder at which point you abstract all those copy/pasted targets into a script that takes an argument.

    [1] https://github.com/facebook/lexical/blob/main/package.json#L...

  • by chaoxu on 6/21/22, 4:17 AM

    Recently I have been testing vditor, vditor is a markdown editor that have a instant rendering feature [1]. If I'm creating my own editor, how hard is it to implement it using Lexical?

    [1] https://github.com/Vanessa219/vditor/blob/master/README_en_U...

  • by rsstack on 6/20/22, 7:14 PM

    I'd love to use Lexical to replace what we're using today. I've been checking in on the repository every few weeks. However, there are many features that are still pending https://github.com/facebook/lexical/projects/1 . We need several of the features that are "V1.0" and we obviously need the stability of a 1.0 SemVer release :)

    Is there a general timeline goal for the V1.0 release?

  • by mhdhn on 6/21/22, 5:47 AM

    There do not seem to be text direction controls. I see it does basic heuristic text direction guessing, apparently based on first strong LTR or RTL character in a paragraph, but this is often not adequate for determining text direction correctly, hence the need for explicit control, at least at the paragraph level, ideally also at subparagraph level. Any plans to add such controls? There are about a billion users of bidirectional languages (Arabic, Hebrew, Farsi, Urdu, Yiddish, et al).
  • by a-priori on 6/20/22, 7:33 PM

    How does this compare to Draft.js, another rich text editor created by Facebook?

    https://draftjs.org/

  • by elvin_d on 6/21/22, 8:13 PM

    I tried most of the existing editors and worked with some of them a lot. Lexical have a nice declarative API; so far, enjoying using it. Even without proper docs, I quickly got an idea of what it is and how to develop. React ecosystem lacked a proper text editor and lexical is really promising.
  • by thorncorona on 6/20/22, 10:22 PM

    I realize this isn't probably your product surface but do you have any idea why FB messenger still has issues with double texting using the text box?

    Also, how do you guys design to reduce latency in Lexical? Esp considering the fluidity of modern chat clients ex. Telegram which are much more performant.

  • by tester756 on 6/20/22, 7:34 PM

    That's really good

    How do people search for jobs that work in this problem domains - parsers / editors / compilers?

  • by chrismorgan on 6/21/22, 10:55 AM

    Hmm, just tried the playground in Firefox on Linux, it’s about as buggy as fancy things like this tend to be.

    • Inserting emoji with my Compose key: some (e.g. U+1F641) get turned into image-backed emoji and then duplicated unless preceded by another image-backed emoji; some (e.g. U+1F928) get ignored and left as normal text.

    • If I type an emoji that gets duplicated while inside a link (but not inside bold/italic), one goes where the caret is, and the other goes immediately before the link, and it leaves the caret there.

    • The image-backed emoji are incompatible with inline text formatting: if you type them in the middle of formatted text, instead of ending up with the likes of <u>text EMOJI text</u>, you end up with <u>text </u>EMOJI<u> text</u>, and although you can subsequently apply the formatting so that it shows in the debug tree, it doesn’t change the HTML markup (e.g. subscript/superscript/underline/code should certainly be visible, and even italic and bold can change emoji rendering).

    • If I select part of a link starting outside the end of a link (that is, go one character past the link and then press the Left arrow key—Firefox has valid caret positions for both inside and outside the start and end of an element, depending on which direction you came from, which my faint recollection was a major trouble point on WebKit many years ago, that you couldn’t do that and so literally couldn’t model various reasonable, kinda like multiple selection which is also Firefox-only and extremely useful on tables) and delete that, instead of just deleting the selected characters, it deletes the entire link. (As above, this seems to be specific to links, not affecting bold/italic.)

    • Very early on (before I had done any editing at all) when I tried the time travel feature, I somehow activated the autocomplete popup on the words “The playground” by clicking or something, even though autocomplete was not turned on (I only confirmed that that was what it was, and not a spelling corrector, by later enabling it and typing “the”) and it was supposed to be read-only.

    • Resizing table rows and columns is very buggy, with things like the grippies easily getting lost, the table-cell-action-button not updating its position, and it sometimes failing to act on mouse up. (Props for including the functionality, though, as it’s normally overlooked.)

    • Clicking in table cells always moves the caret to the start of the cell rather than where you clicked, meaning you have to use arrow keys to get to the right place, and can’t select properly by mouse either.

    • Pop-up menus don’t scroll with the document while open.

    • Autocomplete popup doesn’t close when you move the caret by mouse, though they will no longer work if you click on them.

    • Incidentally, who thought it a good idea to apply `list-style-position: inside`?

    And this was from a fairly quick test. I found most of this stuff immediately and would expect to hit most of these issues in real life.

    I honestly wish people would try to be less fancy with WYSIWYG components, because the web platform just isn’t well-adapted to it.

  • by canadiantim on 6/20/22, 10:19 PM

    Does Lexical require react?
  • by 8organicbits on 6/20/22, 7:23 PM

    How is Facebook using this?
  • by firecall on 6/20/22, 11:17 PM

    Wow, that looks really nice!

    I'm more excited about this than you'd expect LOL

  • by nsonha on 6/21/22, 7:58 AM

    Clickbait title, what does that even mean for a text editor to "power" facebook