sanity-io / block-content-to-hyperscript

Function for transforming Sanity block content to HyperScript
MIT License
17 stars 8 forks source link

Handle unknown block types more gracefully #17

Closed barbogast closed 2 years ago

barbogast commented 4 years ago

At the moment the BlockSerializer throws an error for unknown block types. Could the renderer just render nothing, or an error string, and emit a warning instead of throwing an error?

We use different serializers (react + react-native) for the same content, and we have several custom blocks. This means that it is a real risks for the serializers to get out of sync with the block content, and the result would be an ugly crash of the application.

Another case: We render block content in a mobile app. Even if the serializers get updated properly, a lot of users will not update the app immediately. This means that all old versions of the app would crash once a new block element is used in content that is also loaded by old apps.

barbogast commented 4 years ago

The configuration could offer to pass a errorSerializer. This would be a function that is called with an error object for all errors happening during serialization, and would be expected to return a renderable element.

We would also emit an error report to Sentry in case of an error, which could also be handled in the errorSerializer.

barbogast commented 4 years ago

Hi, I just realised that #13 does exactly what we would need. Would it possible to merge the PR?

balazsorban44 commented 3 years ago

@barbogast it just got merged 🎉

robations commented 2 years ago

@barbogast it just got merged 🎉

Should this issue be closed?

barbogast commented 2 years ago

I guess so, yeah. Closing...