From 58ecf0713628b818af2643f8c9f19c95aec75ee3 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Wed, 22 Jun 2022 13:58:27 +0200 Subject: [PATCH] fix(vue3): state sync breaking after loading story 2nd time, fix #128 --- packages/histoire-plugin-vue/src/client/app/Variant.vue | 2 +- packages/histoire-shared/src/state.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/histoire-plugin-vue/src/client/app/Variant.vue b/packages/histoire-plugin-vue/src/client/app/Variant.vue index 0dc4e6e3..7acdbc1a 100644 --- a/packages/histoire-plugin-vue/src/client/app/Variant.vue +++ b/packages/histoire-plugin-vue/src/client/app/Variant.vue @@ -42,7 +42,7 @@ export default defineComponent({ const implicitState = inject<() => any>('implicitState') watch(() => implicitState, value => { - applyStateToVariant(attrs.variant, value()) + applyStateToVariant(attrs.variant, value(), true) }, { immediate: true, }) diff --git a/packages/histoire-shared/src/state.ts b/packages/histoire-shared/src/state.ts index d3b4dda5..7116826a 100644 --- a/packages/histoire-shared/src/state.ts +++ b/packages/histoire-shared/src/state.ts @@ -24,10 +24,10 @@ export function omit (data, keys: string[]) { return copy } -export function applyStateToVariant (variant: Variant, state: any) { +export function applyStateToVariant (variant: Variant, state: any, override = false) { if (variant.state) { for (const key in state) { - if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) { + if (!override && variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) { Object.assign(variant.state[key], state[key]) } else { variant.state[key] = state[key]