mattelen / vue3-runtime-template

Vue component for compiling templates on the fly using a v-html like API
MIT License
47 stars 12 forks source link

Handle template errors more gracefully #13

Closed jaredmcateer closed 2 years ago

jaredmcateer commented 2 years ago

In the original vue-runtime-template it handled errors gracefully, I assume this is changes in the compiler and not necessarily vue3-runtime-template but errors in the html results in a unhandled DOM error that breaks the rest of the vue app.

image

I've tried configuring a global app instance errorHandler but this error seems to bypass that.

Here is a minimal reproduction: https://github.com/jaredmcateer/vue3-runtime-template-error

mattelen commented 2 years ago

Hi @jaredmcateer thanks for taking the time to figuring this out, and making a repo to replicate with. I've spent a couple of hours playing around with this issue and figuring out the best course of action, and I think the best situation here is that the template should be checked before it is passed to the runtime-template

My main reasoning behind this is thinking around is what should happen if it doesn't pass the HTML test. In the apps that I use it for, we would want to display some sort of stylised error message. While we could create one, developers would need to still stylise it. Alternatively, if they do a check beforehand, they could use their standard message/error component they have in their app and display it. It also creates a more stable app as if we have our error wrapped in a class, and update a CSS class or something, the styling may break. We could also offer slots etc, but then comes the question of how strict do you the tests to be, and what checks are allowed to fail, and what aren't.

So if you are in a situation where you need checks to be done, I would recommend doing the checks in your app before passing the code to the runtime-template. You can then also decide how strict the checks are. I was playing around with different HTML code checks today, and some said my template was fine, and others said it wasn't but it was still able to render my template.

Hope this thinking helps, and thanks again for opening up an issue. Would love to hear your thoughts around this, so please let me know, but in the meantime I'll close this issue