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: guard against nullable markDefs #96

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

bobinska-dev
Copy link
Contributor

Marking markDefs as optional to resolve TS error when markDefs array is missing

Copy link
Member

@christianhg christianhg left a comment

Choose a reason for hiding this comment

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

Looks like a safe addition to safe guard against a potential nullable markDef!

@jepezi
Copy link

jepezi commented Feb 6, 2025

Awesome, I ran into this problem today and about to submit pr but @bobinska-dev beated me to it! In case someone has the same problem, here's context from slack.

Hi! I'm getting an error [ Server ] Error: Cannot read properties of null (reading 'find') when I copy and paste the nested block content in the same field of same document type. The error comes from serializeBlock function in react-portable-text module where it tries to buildMarksTree. I log the data and found that the original field always has "markDefs": [] and "marks": [] set to empty array but the field where I pasted into contain markDefs: null and marks: null. Is this a bug in copy and paste feature or do I have to change any of my schema?

here's the part of the data

"content": [
  {
    "_key": "1d6d03fd419e",
    "_type": "block",
    "style": "normal",
    "markDefs": null, // <----- this is the problem
    "children": [
      {
        "_key": "d0a5a756499b",
        "_type": "span",
        "text": "sample text"
      }
    ],
  },
]

@christianhg christianhg added this pull request to the merge queue Feb 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2025
@christianhg christianhg changed the title fix(typeError): null value for markDefs array fix: guard against nullable markDefs Feb 6, 2025
@christianhg christianhg added this pull request to the merge queue Feb 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2025
@christianhg christianhg added this pull request to the merge queue Feb 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2025
@christianhg christianhg added this pull request to the merge queue Feb 6, 2025
Merged via the queue into portabletext:main with commit eedd7c7 Feb 6, 2025
7 checks passed
@ecoscript ecoscript bot mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants