histoire-dev / histoire

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

Initial state overwritten when coming back to story #228

Closed victorlmneves closed 2 years ago

victorlmneves commented 2 years ago

Describe the bug

Creating a new state on Controls throws an error when switching between existing states. It switches once, and then it no longer is possible to switch back to another option.

state.js?v=f51ce856:6 DOMException: Failed to execute 'structuredClone' on 'Window': #<Object> could not be cloned.
    at clone (http://localhost:6600/node_modules/@histoire/shared/dist/state.js?v=f51ce856:3:16)
    at applyPreset (http://localhost:6600/node_modules/histoire/dist/bundled/components/panel/StatePresets.js:45:41)
    at createVNode.onSelect._cache.<computed>._cache.<computed> (http://localhost:6600/node_modules/histoire/dist/bundled/components/panel/StatePresets.js:115:57)
    at callWithErrorHandling (http://localhost:6600/node_modules/@histoire/vendors/dist/client/vue.runtime.esm-bundler.js?v=f51ce856:1993:22)
    at callWithAsyncErrorHandling (http://localhost:6600/node_modules/@histoire/vendors/dist/client/vue.runtime.esm-bundler.js?v=f51ce856:2002:21)
    at emit$1 (http://localhost:6600/node_modules/@histoire/vendors/dist/client/vue.runtime.esm-bundler.js?v=f51ce856:2559:9)
    at http://localhost:6600/node_modules/@histoire/vendors/dist/client/vue.runtime.esm-bundler.js?v=f51ce856:9181:53
    at selectValue (http://localhost:6600/node_modules/histoire/dist/bundled/components/base/BaseSelect.js:45:7)
    at onClick (http://localhost:6600/node_modules/histoire/dist/bundled/components/base/BaseSelect.js:58:38)
    at callWithErrorHandling (http://localhost:6600/node_modules/@histoire/vendors/dist/client/vue.runtime.esm-bundler.js?v=f51ce856:1993:22) 'Fallback to JSON cloning'

Reproduction

Just open one of the existing stories, create a new state on the Controls, and switch between them.

https://stackblitz.com/edit/histoire-vue3-starter-uapwc2

System Info

System:
    OS: macOS 12.5
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 219.45 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
  Browsers:
    Brave Browser: 104.1.42.86
    Chrome: 103.0.5060.134
    Firefox: 103.0.1
    Safari: 15.6

Used Package Manager

npm

Validations

Akryum commented 2 years ago

Does it works anyway? This a warning that has a fallback when the browser can't do a structured clone of your state.

victorlmneves commented 2 years ago

@Akryum it works while you are on the story. If you go to a different story and then return to the story it no longer switches between the existing states

Akryum commented 2 years ago

Looks like the issue is in reality "the initial state is not the initial one but the one from last state when coming back to the story". Switching between presets still works.

Akryum commented 2 years ago

I've implemented a series of improvements that should fix this:

victorlmneves commented 2 years ago

thanks @Akryum