uiwjs / uiwjs/react-md-editor

Editor shows [object Object] instead of text

Open
#349 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.9k
Forks
201
Avg merge
12m
Merged PRs (30d)
1

Description

Hi,
I am using this markdown editor and generally, it works amazingly (thanks :) )
However there is a strange issue with it:
At the first rendering, the editor side renders strange symbols in the form of [object Object] instead of the actual text:
image
The bad symbols are not selectable, instead when trying to copy them, the correct text is displayed. Also changing something in the editor immediately fixes the problem.
This is how the element looks like in dev tools:
image

And here is the react component I am using to render it:


import loadable from '@loadable/component';
const MDEditor = loadable(() => import('@uiw/react-md-editor'))
import { useState } from "react"
import { Link, useNavigate, useParams } from "react-router-dom"
import { useAddImageMutation, useAddProjectTagMutation, useDeleteProjectMutation, useGetProjectByIdQuery, useRemoveImageMutation, useRemoveProjectTagMutation, useUpdateImageDescriptionMutation, useUpdateProjectDescriptionMutation, useUpdateProjectNameMutation } from "../schemas"
import Button from "../shared/Button"
import Input from "../shared/Input"
import "./projectEditor.css"
import useConfig from "../config";
import TagSelector from '../shared/tagSelector/TagSelector';


export const ProjectEditor: React.FC = props => {
    const params = useParams()
    const projectId = params["id"]
    const config = useConfig()
    const [description, setDescription] = useState<string | null>(localStorage.getItem("description#" + projectId))
    const projectData = useGetProjectByIdQuery({
        variables: { id: projectId || "" }, onCompleted: (data) => {
            setDescription(data?.getProject?.description || "")
        }
    })
...
    const [updateProjectDescription] = useUpdateProjectDescriptionMutation()
    if (!projectId) {
        return <Link to="/">Invalid URL! Go home</Link>
    }
    if (!projectData.data?.getProject) {
        return <Link to="/">Invalid Project ID! Go home</Link>
    }
    return (
        <div className="project-editor">
            <h1>Edit project "{projectData.data?.getProject?.name}"</h1>
            ...
            {description !== null && <div className="project-editor-component">
                <h2>Description</h2>
                <MDEditor value={description} preview={config.view == "mobile" ? "edit" : undefined}
                    onChange={(newDescription) => {
                        setDescription(newDescription || null)
                    }}
                />
                <Button onClick={() => {
                    const newDescription = description || ""
                    setDescription(null)
                    updateProjectDescription({ variables: { newDescription, projectId: projectId } })
                        .then((res) => {
                            if (res.data?.projectMutation?.updateDescription) {
                                projectData.refetch().then(() => {
                                    setDescription(newDescription)
                                })
                            } else {
                                alert(res.errors?.join(""))
                                setDescription(newDescription)
                            }
                        }).catch((r) => {
                            alert("Could not update description")
                            setDescription(newDescription)
                        })

                }}>Save</Button>

            </div>}
          ...
        </div>
    )
}

Interestingly this issue only occurs in the bundle and not in the dev mode (vitejs) which makes it hard to debug.
Am I doing something wrong or is this an actual bug?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided ProjectEditor and MDEditor usage, comparing the production bundle with Vite dev mode. Inspect the initial rendering path and confirm that the editor displays the actual markdown text rather than [object Object] before any edit.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript, vite
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.