m4rvr / storyblok-rich-text-renderer

Fast renderer for your rich-text content.
35 stars 15 forks source link

RichTextRenderer not respecting v-show #19

Closed fanckush closed 2 years ago

fanckush commented 2 years ago

Hey again, It's possible this is caused by other factors but the following code doesn't work:

<RichTextRenderer
  v-show="false"
  :document="theDoc"
/>

while this works:

<div v-show="false">
  <RichTextRenderer  :document="theDoc"  />
</div>

and this works too:

<RichTextRenderer
  v-if="false"
  :document="theDoc"
/>

I'm using V3.2

Edit maybe related https://github.com/vuejs/vue/issues/1388

m4rvr commented 2 years ago

Hey! The console shows

CleanShot 2022-01-20 at 13 33 55@2x

which is because the component doesn't have a root node but renders the content as fragments.

You can either do it like you already do it (with a separate div) or you could change the resolver of NodeTypes.DOCUMENT. Currently, it renders just the children but you could modify it to something like ({ children }) => h('div', children). This ensures that it renders the content of the rich text always inside a <div>.

In Vue 2 it was always there because fragments weren't allowed.

fanckush commented 2 years ago

Aaah that makes sense. Thanks for the clarification