From 69b1d233ce0fe10bd4d15a59ffdac6466d928e7d Mon Sep 17 00:00:00 2001 From: Makoto Morimoto Date: Wed, 29 Nov 2023 07:20:42 -0800 Subject: [PATCH] fix: Preventing multiple 'Open in CodeSandbox' buttons being added when switching themes (#29932) * fix: Preventing multiple 'Open in CodeSandbox' buttons being added when switching themes. * Testing for all possible options, and not only for CodeSandbox. * Addressing PR feedback. --- .../src/sandbox-utils.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/react-components/react-storybook-addon-export-to-sandbox/src/sandbox-utils.ts b/packages/react-components/react-storybook-addon-export-to-sandbox/src/sandbox-utils.ts index e5f534fc0f739..72b99b8a6e718 100644 --- a/packages/react-components/react-storybook-addon-export-to-sandbox/src/sandbox-utils.ts +++ b/packages/react-components/react-storybook-addon-export-to-sandbox/src/sandbox-utils.ts @@ -30,11 +30,9 @@ export function prepareSandboxContainer(context: StoryContext) { const classList = (showCodeButton.classList.value + ' with-code-sandbox-button').split(' '); - // this is needed in dev loop as every hot reload will add new buttons - if (process.env.NODE_ENV !== 'production') { - const ourButtons = container.querySelectorAll(`.with-code-sandbox-button`); - ourButtons.forEach(node => node.remove()); - } + // remove button if it already existed + const ourButtons = container.querySelectorAll(`.with-code-sandbox-button`); + ourButtons.forEach(node => node.remove()); return { container,