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

Give markDefs a fallback value if it is null #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hjalm8
Copy link

@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')

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.

1 participant