Storybook: fix Emotion jsxImportSource - #80426
Conversation
Pre-bundle CJS deps so Vite exposes a default export for Emotion.
|
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. |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 7.73 MB |
|
@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 |
|
If the fix works for you too, feel free to merge this PR 🚀 |
|
Great! I didn't have time yet to dig into this at all, glad it's sorted and better now :) |
|
Flaky tests detected in 4ea310a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29615484072
|
| dsTokenFallbacksJs(), | ||
| react( { | ||
| jsxImportSource: getAbsolutePath( '@emotion/react' ), | ||
| jsxImportSource: '@emotion/react', |
There was a problem hiding this comment.
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.
*/
What?
Pre-bundle CJS deps so Vite exposes a default export for Emotion.
In trunk running
npm run storybook:e2e:devwas broken:Why?
How?
Testing Instructions
Run
npm run storybook:e2e:devConfirm it loads.
Testing Instructions for Keyboard
Use of AI Tools
completely