histoire-dev / histoire

⚡ Fast and beautiful interactive component playgrounds, powered by Vite
https://histoire.dev
MIT License
3.16k stars 186 forks source link

Vue 3 - Erroneous properties show in preview when using init-state #736

Open hybridwebdev opened 3 months ago

hybridwebdev commented 3 months ago

Describe the bug

Consider the following story:

<script setup>
import { ref } from 'vue'
import { logEvent } from 'histoire/client'
import BaseButton from './BaseButton.vue'
let initStateNoBeuno = () => ({
  color: "#f00",
})
let initStateBeuno = () => ({
    props:  {
      color: "#f00"
    }
})
const text = ref('Click me')
</script>

<template>
  <Story >

    <Variant 
        #default='{ state }' :init-state="initStateNoBeuno"
        title='Unexpected properties'
      >
      <BaseButton v-bind="state">
        {{ text }}
      </BaseButton>
    </Variant>

    <Variant 
      #default='{ state }'
      :init-state="initStateBeuno"
      title='Nesting works'
    >
      <BaseButton v-bind="state.props">
        {{ text }}
      </BaseButton>
    </Variant>

    <template #controls>
      <HstText title="default slot" v-model="text" />
    </template>
  </Story>
</template>

When using the init-state property, either on a story or a variant, unexpected properties show in the dynamic source preview as shown in the screen shot:

image

If you use a nested property, then these properties disappear.

Reproduction

https://stackblitz.com/edit/histoire-vue3-starter-nqsezx?file=src%2FBaseButton.story.vue

System Info

Issue occurs using VUE 3.3 but also in provided sandbox environment.

Used Package Manager

npm

Validations

stackblitz[bot] commented 3 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.