From f1541ceead666beb61c9768a43458f3733cbc693 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Thu, 5 Mar 2026 03:16:00 +0900 Subject: [PATCH 1/2] Storybook: Deduplicate injected package stylesheets Extract shared ref-counted style injection into useSharedStyle hook, used by both WithRTL and WithGlobalCSS decorators. --- .../decorators/utils/use-shared-style.ts | 57 +++++++++++++++++++ storybook/decorators/with-global-css.jsx | 12 ++-- storybook/decorators/with-rtl.jsx | 41 ++++++------- 3 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 storybook/decorators/utils/use-shared-style.ts diff --git a/storybook/decorators/utils/use-shared-style.ts b/storybook/decorators/utils/use-shared-style.ts new file mode 100644 index 00000000000000..297d4b0566e8fc --- /dev/null +++ b/storybook/decorators/utils/use-shared-style.ts @@ -0,0 +1,57 @@ +import { useLayoutEffect } from '@wordpress/element'; + +interface StyleEntry { + element: HTMLStyleElement; + refCount: number; +} + +const styleRefs = new Map< string, StyleEntry >(); + +/** + * Injects a `