Skip to content

Storybook: fix Emotion jsxImportSource - #80426

Merged
simison merged 4 commits into
trunkfrom
fix/storybook-e2e
Jul 17, 2026
Merged

Storybook: fix Emotion jsxImportSource#80426
simison merged 4 commits into
trunkfrom
fix/storybook-e2e

Conversation

@simison

@simison simison commented Jul 17, 2026

Copy link
Copy Markdown
Member

What?

Pre-bundle CJS deps so Vite exposes a default export for Emotion.

In trunk running npm run storybook:e2e:dev was broken:

Screenshot 2026-07-17 at 21 51 33 Screenshot 2026-07-17 at 21 51 21

Why?

How?

Testing Instructions

Run npm run storybook:e2e:dev
Confirm it loads.

Testing Instructions for Keyboard

Use of AI Tools

completely

Pre-bundle CJS deps so Vite exposes a default export for Emotion.
@simison
simison requested a review from a team July 17, 2026 18:54
@simison simison added [Type] Bug An existing feature does not function as intended Storybook Storybook and its stories for components labels Jul 17, 2026
@simison

simison commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

I didn't have time to bisect which commit broke this, but I saw some Emotion related PRs from @ciampo so likely one of those? Anyway, this fixes it.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: simison <simison@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.73 MB

compressed-size-action

@ciampo
ciampo requested a review from desrosj as a code owner July 17, 2026 21:26
@ciampo

ciampo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@simison, rather than posting a comment with a convoluted explanation, I just pushed a follow-up with a different approach.

The absolute Emotion path was bypassing Vite’s normal package resolution, which caused Emotion to be loaded through two different module paths. Restoring the regular @emotion/react package import lets Vite optimize it normally and keeps a single shared Emotion instance.

@ciampo

ciampo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

If the fix works for you too, feel free to merge this PR 🚀

@simison

simison commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Great! I didn't have time yet to dig into this at all, glad it's sorted and better now :)

@simison
simison enabled auto-merge (squash) July 17, 2026 21:44
@simison simison changed the title Storybook: pre-bundle CJS deps Storybook: fix Emotion jsxImportSource Jul 17, 2026
@simison
simison merged commit d023c34 into trunk Jul 17, 2026
43 checks passed
@simison
simison deleted the fix/storybook-e2e branch July 17, 2026 22:13
@github-actions github-actions Bot added this to the Gutenberg 23.7 milestone Jul 17, 2026
@github-actions

Copy link
Copy Markdown

Flaky tests detected in 4ea310a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29615484072
📝 Reported issues:

Comment thread storybook/main.ts
dsTokenFallbacksJs(),
react( {
jsxImportSource: getAbsolutePath( '@emotion/react' ),
jsxImportSource: '@emotion/react',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, we will need to set an alias for this; otherwise, it will break the isolated build.

diff --git a/storybook/main.ts b/storybook/main.ts
index 36358c13df1..fd266c7de2c 100644
--- a/storybook/main.ts
+++ b/storybook/main.ts
@@ -224,6 +224,16 @@ const config: StorybookConfig = {
 				),
 			},
 			resolve: {
+				alias: {
+					/*
+					 * `jsxImportSource` injects `@emotion/react` into every JSX
+					 * file, including stories in packages that don't depend on
+					 * it (e.g. block-editor) and can't resolve it under the
+					 * isolated dependency layout. Alias it to this workspace's
+					 * copy — the one all consumers already resolve to.
+					 */
+					'@emotion/react': getAbsolutePath( '@emotion/react' ),
+				},
 				/*
 				 * Resolve Storybook packages from this workspace.
 				 */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better yet: We can remove this altogether? 🙂 #80647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storybook Storybook and its stories for components [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants