From d9a1b43044250eac94138b0554585ff4c1fb3411 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Tue, 7 Apr 2020 12:07:58 -0700 Subject: [PATCH] fix: always destroy old Marko component when switching stories --- app/marko/src/client/preview/render.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/marko/src/client/preview/render.js b/app/marko/src/client/preview/render.js index 24486a583dc5..f314429c8384 100644 --- a/app/marko/src/client/preview/render.js +++ b/app/marko/src/client/preview/render.js @@ -6,6 +6,7 @@ import { logger } from '@storybook/client-logger'; const rootEl = document.getElementById('root'); let activeComponent = null; // currently loaded marko component. let activeTemplate = null; // template for the currently loaded component. +let activeStoryFn = null; // used to determine if we've switched stories. export default function renderMain({ storyFn, @@ -16,7 +17,9 @@ export default function renderMain({ parameters, // forceRender, }) { + const isSameStory = activeStoryFn === storyFn; const config = storyFn(); + activeStoryFn = storyFn; if (!config || !(config.appendTo || config.component || parameters.component)) { showError({ @@ -43,7 +46,7 @@ export default function renderMain({ } else { const template = config.component || parameters.component; - if (activeTemplate === template) { + if (isSameStory && activeTemplate === template) { // When rendering the same template with new input, we reuse the same instance. activeComponent.input = config.input; activeComponent.update();