static-html.js 858 B

123456789101112131415161718192021222324252627282930313233
  1. import { h, defineComponent } from 'vue';
  2. /**
  3. * Astro passes `children` as a string of HTML, so we need
  4. * a wrapper `div` to render that content as VNodes.
  5. *
  6. * This is the Vue + JSX equivalent of using `<div v-html="value" />`
  7. */
  8. const StaticHtml = defineComponent({
  9. props: {
  10. value: String,
  11. name: String,
  12. hydrate: {
  13. type: Boolean,
  14. default: true,
  15. },
  16. },
  17. setup({ name, value, hydrate }) {
  18. if (!value) return () => null;
  19. let tagName = hydrate ? 'astro-slot' : 'astro-static-slot';
  20. return () => h(tagName, { name, innerHTML: value });
  21. },
  22. });
  23. /**
  24. * Other frameworks have `shouldComponentUpdate` in order to signal
  25. * that this subtree is entirely static and will not be updated
  26. *
  27. * Fortunately, Vue is smart enough to figure that out without any
  28. * help from us, so this just works out of the box!
  29. */
  30. export default StaticHtml;