Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

NtchPlayer
Copy link
Contributor

@NtchPlayer NtchPlayer commented Nov 2, 2023

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:

  • If a the plugin can't render the code (ie. with syntax like that <UnknowComponent>) with vueTemplate enabled, render the code without template, components and setup
  • And if syntax is fixed switch again to render with vueTemplateoptions.

Copy link

vercel bot commented Nov 2, 2023

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

NtchPlayer commented Nov 18, 2023

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 😃

@meteorlxy meteorlxy closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Handle template error when vueTemplate is active
2 participants