splitbee / react-notion

A fast React renderer for Notion pages
https://react-notion.com
MIT License
2.85k stars 149 forks source link

Handling null properties values #108

Open jeanmw opened 1 year ago

jeanmw commented 1 year ago
      case "video":
        var value = block.value;
        return /*#__PURE__*/createElement("figure", {
          className: "notion-asset-wrapper",
          style: value.format !== undefined ? {
            width: value.format.block_width
          } : undefined
        }, /*#__PURE__*/createElement(Asset, {
          block: block,
          mapImageUrl: mapImageUrl
        }), value.properties.caption && /*#__PURE__*/createElement("figcaption", {
          className: "notion-image-caption"
        }, renderChildText(value.properties.caption)));

This generated block in react-notion.esm.js is failing when properties are null. Properties are not always present in this case and therefore there can be a failure here with .caption in the chain. I'm not sure the best way to handle this - is the onus on the notion doc creator to ensure no null properties values? (this could happen if an unfinished video component was inserted in a doc and mistakenly forgotten about).

Should properties be required on ContentValueType? on All values? Should properties be required? Can we make them nullable, or is that an antipattern?