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 markDefs being null #92

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

hjalm8
Copy link
Contributor

@hjalm8 hjalm8 commented Aug 7, 2024

Default values during a destructuring assignment are not used when the value is null.

Example from MDN:

const [a = 1] = []; // a is 1
const { b = 2 } = { b: undefined }; // b is 2
const { c = 2 } = { c: null }; // c is null

I encountered this PortableText block:

[
  {
    "_type": "block",
    "style": "normal",
    "_key": "3f2160c15ba9",
    "children": [
      {
        "_type": "span",
        "marks": [
          "em"
        ],
        "text": "Example",
        "_key": "d8bf318b9723"
      }
    ]
  }
]

This caused rendering to crash when using the PortableText component from portabletext/react.
Specifically ./src/buildMarksTree.ts:93 Error: Cannot read properties of null (reading 'find')

@christianhg christianhg changed the title Give markDefs a fallback value if it is null fix: guard against markDefs being null Feb 6, 2025
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.

Thank you!

@christianhg christianhg added this pull request to the merge queue Feb 6, 2025
Merged via the queue into portabletext:main with commit 1f1644a 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.

2 participants