diff --git a/packages/html/.storybook/preview.ts b/packages/html/.storybook/preview.ts
index b8a8936337..7265443ea2 100644
--- a/packages/html/.storybook/preview.ts
+++ b/packages/html/.storybook/preview.ts
@@ -24,6 +24,12 @@ const resetMaxGraphConfigs = (): void => {
resetVertexHandlerConfig();
};
+// This function is a workaround to destroy mxGraph elements that are not released by the previous story.
+// See https://github.com/maxGraph/maxGraph/issues/400
+function destroyUnreleasedElements() {
+ document.querySelectorAll('.mxPopupMenu,.mxWindow').forEach((e) => e.remove());
+}
+
const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
@@ -39,6 +45,7 @@ const preview: Preview = {
// inspired by https://github.com/storybookjs/storybook/issues/4997#issuecomment-447301514
(storyFn) => {
resetMaxGraphConfigs();
+ destroyUnreleasedElements();
return storyFn();
},
],