Placeholder for broken images

I’m trying to create an editor plugin that replaces images that fails to load with a broken image graphic.

I’ve looked at using decorators but see no way to access the dom node from there to attach an onerror event listener. I’ve looked at attaching it in the toDOM method of my schema but that seems wrong, and I’m not sure how I would go about updating the state from there.

Anyone have suggestions on how to best implement such a feature?

A node view could probably do this (create the node, attach event handler that triggers some logic when an error event happens), but I think a cleaner way would be to create img nodes off the side to build up a table of the validity of urls, and use that to create the decorations.

1 Like