meteorlxy / vue-showdown

:page_with_curl: Use showdown as a vue component
https://vue-showdown.js.org
MIT License
129 stars 23 forks source link

feat(vueTemplate): add try catch on render function to avoid compiler error #53

Closed NtchPlayer closed 5 months ago

NtchPlayer commented 11 months ago

Add a try...catch to render function to avoid error if vueTemplate compiler encountered an error.

To fix issue 52.

Sadly, I don't know how to run the package in production mode, so I can't test this solution to see if it's works correctly.

The behaviour expected is:

vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue-showdown ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 18, 2023 3:20pm
NtchPlayer commented 10 months ago

Hi again !

Use a try...catch to handle compilation error don't work, so I found another way to do it :D

I add a new function checkHTMLStructure, that use DOMParser to check if HTML provide to render function is correct.

If it's not, I render markdown without vue render. I test it in production and it's work 😄.

meteorlxy commented 10 months ago

Hi. Sorry for delay. Thanks for the solution! However, I'm a little concerned that validating dom could be too heavy for this library. Maybe we could find a more light-weighted & elegant way to handle that error.

BTW, please do not include dist dir in the PR. Those dist files would be updated when creating a new release. Thanks!

NtchPlayer commented 10 months ago

Oh, sorry for the dist file, I would be careful not to add it next time !

To be honest I spended my 3 last day on that error to try to find an solution, and it's the only solution that I found 😢. But I agree with you, this solution is pretty hard to just handle a error...

I try a lot to find a way to handle error from h function error, but I found nothing (I even ask on VueLand, the discord server of Vue, but without more success...)

After some investigation, I found that the real problem is, when h render function throw an error, the parent div (the div where markdown is render) is remove from the DOM, and after that, the plugin can't render markdown. It's like the h function is unlink from the DOM So even if you fix your markdown, the only way to repair the module is to hard reload your page.

I try to add key, to force a rerender of the component, but it's not worked too.

So I conclude that, if I can't handle the error or reboot the component, my last solution is to prevent the error.

I really need a fix now, even if it's not perfect (to be honnest in my use-case I don't really care about performance), so I will continue to use my version of the package, (I can't really take time to find another fix now), but if you have any idea or a potential fix, let me know, I would be happy to help 😃

dword-design commented 3 months ago

Why is the MR closed? 😀