mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.81k stars 138 forks source link

Bug - Link Dialogue State Management #350

Closed fredachang closed 5 months ago

fredachang commented 7 months ago

Hello Petyo,

Thank you for releasing version 2 - everything is working wonderfully except for one minor bug that may be unique to my application. I have tried to trouble shoot but am stuck - I was wondering if you are able to give me some pointers?

Issue:

However the problem is we are hiding the title column with custom css as we don't need titles for links in our application.

I think the issue has got something to do with the title column being empty, but only on update.

Unfortunately I've run your latest code base locally and cannot reproduce the error there, so this may be unique to scenarios where the link data is saved permanently to an external database and not just locally.

Let me know if you have any clues as to why this may be happening.

Much appreciated, Freda

petyosi commented 7 months ago

The stack you posted does not seem related to the link dialog - as far as I can see, it's going somewhere in the codemirror instance.

If you can reproduce it in a sandbox, I should be able to help you further. I will close in the meantime, but please let me know if you manage to give me a reproduction.

jpreis commented 5 months ago

We've also encountered this issue in our project. We have the exact same use case as @fredachang, we don't need titles for our links and would thus also hide the corresponding input.

The error @fredachang described can be reproduced on the MDXEditor live demo:

Bildschirmfoto 2024-04-03 um 16 55 28

I think this might have to do with the initialization of the form state inside LinkDialog.tsx

...
export function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggestions }: LinkEditFormProps) {
  const {
    register,
    handleSubmit,
    control,
    setValue,
    reset: _
  } = useForm<LinkFormFields>({
    values: {
      url,
      title
    }
  })

I assume for some reason this gets initialized as undefined instead of empty string when the link was previously created with an empty title. I was able to work around this with the following adjustment:

...
export function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggestions }: LinkEditFormProps) {
  const {
    register,
    handleSubmit,
    control,
    setValue,
    reset: _
  } = useForm<LinkFormFields>({
    values: {
      url,
      title: title ?? ""
    }
  })

Regarding the described use case: It would be great to have an option to hide the title field via the plugin's API - currently, we have to use some hacky CSS to achieve this :)

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 2.20.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: