Skip to content

feat(pack): support emotion react transform#2682

Merged
xusd320 merged 5 commits into
nextfrom
support-emotion-transform
Mar 12, 2026
Merged

feat(pack): support emotion react transform#2682
xusd320 merged 5 commits into
nextfrom
support-emotion-transform

Conversation

@fireairforce

Copy link
Copy Markdown
Member

Summary

Support style.emotion to enable emotion react transform to support some internal business project:

image

Compitable with: https://makojs.dev/docs/config#emotion

Test Plan

Added.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive support for the Emotion React transform, allowing projects to seamlessly integrate Emotion for styling. It provides a new configuration option to activate the transform and ensures its proper application within the compilation pipeline, enhancing styling capabilities for React applications.

Highlights

  • Emotion React Transform Support: Enabled the transform_emotion feature in turbopack-ecmascript-plugins and integrated the Emotion transform rule into the client module options context.
  • Configuration Option: Introduced a new emotion boolean option within StyleConfig to allow users to enable or disable the Emotion React transform.
  • Snapshot Tests: Added new snapshot tests to validate the correct application and output of the Emotion React transform, ensuring compatibility and proper functionality.
Changelog
  • crates/pack-core/Cargo.toml
    • Enabled the transform_emotion feature for turbopack-ecmascript-plugins.
  • crates/pack-core/src/client/context.rs
    • Imported and registered the get_emotion_transform_rule in the client module options context.
  • crates/pack-core/src/config.rs
    • Added an emotion boolean option to the StyleConfig struct.
  • crates/pack-core/src/shared/transforms/emotion.rs
    • Created a new module to define the get_emotion_transform_rule function, which applies the Emotion transform based on configuration.
  • crates/pack-core/src/shared/transforms/mod.rs
    • Exported the new emotion module.
  • crates/pack-schema/src/lib.rs
    • Added the emotion field with documentation to the SchemaStyleConfig struct.
  • crates/pack-tests/tests/snapshot/basic/jsx/output/_project___e95e9ae8.js
    • Added stub functions for css, Global, and keyframes from @emotion/react.
  • crates/pack-tests/tests/snapshot/basic/jsx/output/_project___e95e9ae8.js.map
    • Updated the source map to reflect the added stub functions.
  • crates/pack-tests/tests/snapshot/node_modules/@emotion/react/index.js
    • Added stub exports for css, Global, and keyframes.
  • crates/pack-tests/tests/snapshot/style/emotion_react/config.json
    • Added a new configuration file to enable Emotion for testing.
  • crates/pack-tests/tests/snapshot/style/emotion_react/input/index.tsx
    • Added a new test file demonstrating Emotion styling in a React component.
  • crates/pack-tests/tests/snapshot/style/emotion_react/output/_project___e35ffa5c.js
    • Added the expected JavaScript output snapshot for the Emotion React test case.
  • crates/pack-tests/tests/snapshot/style/emotion_react/output/main.js
    • Added the main JavaScript output snapshot for the Emotion React test case.
  • crates/pack-tests/tests/snapshot/umd/basic/output/main.js
    • Added stub functions for css, Global, and keyframes from @emotion/react.
  • crates/pack-tests/tests/snapshot/umd/basic/output/main.js.map
    • Updated the source map to reflect the added stub functions.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@xusd320

xusd320 commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

还真有人用这个啊

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for Emotion's React transform, which is a great feature. The implementation is mostly correct, with new configuration options, transform logic, and comprehensive tests. I've confirmed the critical issue in the error handling of the new transform rule that could lead to compilation errors, and the minor formatting issue that affects code readability. My review includes suggestions to address these points.

Comment on lines +21 to +26
let module_rule =
EmotionTransformer::new(&EmotionTransformConfig::default()).map(|transformer| {
get_ecma_transform_rule(Box::new(transformer), false, EcmascriptTransformStage::Main)
});

Ok(module_rule)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The current implementation appears to have a type mismatch that would likely cause a compilation error. Assuming EmotionTransformer::new returns a Result, module_rule would be of type Result<ModuleRule, _>. Wrapping this in Ok() results in a Result<Result<ModuleRule, _>, _>, which does not match the function's required return type of Result<Option<ModuleRule>>.

To fix this and correctly handle potential errors from EmotionTransformer::new, you can chain .map(Some) to the result and return it directly. This will correctly wrap the ModuleRule in an Option while preserving the Result for error propagation.

Suggested change
let module_rule =
EmotionTransformer::new(&EmotionTransformConfig::default()).map(|transformer| {
get_ecma_transform_rule(Box::new(transformer), false, EcmascriptTransformStage::Main)
});
Ok(module_rule)
EmotionTransformer::new(&EmotionTransformConfig::default())
.map(|transformer| {
get_ecma_transform_rule(Box::new(transformer), false, EcmascriptTransformStage::Main)
})
.map(Some)

css_modules::get_auto_css_modules_rule,
default_export_namer::get_default_export_namer_rule,
remove_console::get_remove_console_transform_rule,
emotion::get_emotion_transform_rule, remove_console::get_remove_console_transform_rule,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better readability and to adhere to standard Rust formatting conventions, it's best to have one use path per line within a multi-line use statement.

Suggested change
emotion::get_emotion_transform_rule, remove_console::get_remove_console_transform_rule,
emotion::get_emotion_transform_rule,
remove_console::get_remove_console_transform_rule,

@xusd320

xusd320 commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

我记得之前要在 import_map 里配置 emotion 这个包来着,确认下

@fireairforce

Copy link
Copy Markdown
Member Author

我记得之前要在 import_map 里配置 emotion 这个包来着,确认下

import_source 要处理一下,补了两种测试 case,这个估计后面还要调整一下

@github-actions

Copy link
Copy Markdown

📊 Performance Benchmark Report (with-antd)

Utoopack Performance Report (Intelligent)

Report ID: utoopack_performance_report_20260312_091608
Generated: 2026-03-12 09:16:08
Trace File: trace_antd.json (0.6GB, 3.32M events)
Test Project: examples/with-antd


Executive Summary

Key Findings

Metric Value Assessment
Total Wall Time 8,584.9 ms Baseline
Total Thread Work (de-duped) 27,576.8 ms Non-overlapping busy time
Effective Parallelism 3.2x thread_work / wall_time
Working Threads 5 Threads with actual spans
Thread Utilization 64.2% 🆗 Average
Total Spans 1,658,405 All B/E + X events
Meaningful Spans (>= 10us) 575,498 (34.7% of total)
Tracing Noise (< 10us) 1,082,907 (65.3% of total)

Workload Distribution by Tier

Category Tasks Total Time (ms) % of Thread Work
P0: Runtime/Resolution 0 0.0 0.0%
P1: I/O & Heavy Tasks 39,718 3,719.6 13.5%
P3: Asset Pipeline 36,519 3,419.6 12.4%
P4: Bridge/Interop 0 0.0 0.0%
Other 499,261 22,781.8 82.6%

🤖 AI Intelligent Attributions

New section mapping granular tasks to bottlenecks.

Top 10 Batching Candidates

These highly-called tasks are dominated by a single parent. If the parent can batch them into one call, it drastically reduces scheduler overhead.

Task Name Count Top Caller (Attribution) Avg P95 Total Time
analyze ecmascript module 36,824 process module (76%) 99.0 us 0.29 ms 3,644.3 ms

Top 20 Tasks by Total Duration

Total (ms) Count Avg (us) P95 (ms) Max (ms) % Work Task Name Top Caller
8,296.4 212,105 39.1 0.1 13.3 30.1% module write all entrypoints to disk (1%)
4,024.2 71,370 56.4 0.1 203.4 14.6% process module module (16%)
3,644.3 36,824 99.0 0.3 203.3 13.2% analyze ecmascript module process module (76%)
2,868.1 25,018 114.6 0.4 98.5 10.4% code generation chunking (7%)
1,873.3 68,630 27.3 0.0 5.7 6.8% resolving module (31%)
1,636.3 61,749 26.5 0.0 5.4 5.9% internal resolving resolving (30%)
1,414.7 34,104 41.5 0.1 8.3 5.1% precompute code generation code generation (30%)
1,390.3 15,082 92.2 0.2 53.0 5.0% chunking write all entrypoints to disk (0%)
1,167.0 14,146 82.5 0.3 135.7 4.2% compute async module info chunking (0%)
1,146.6 8,670 132.2 0.1 267.6 4.2% write all entrypoints to disk None (0%)
1,018.2 8,065 126.2 0.5 32.5 3.7% parse ecmascript analyze ecmascript module (26%)
633.2 11,215 56.5 0.1 49.2 2.3% compute async chunks compute async chunks (0%)
300.2 1,936 155.1 0.4 16.9 1.1% generate source map code generation (96%)
114.5 875 130.9 0.0 23.1 0.4% compute binding usage info write all entrypoints to disk (0%)
65.3 2,166 30.2 0.0 1.9 0.2% read file parse ecmascript (91%)
62.3 215 289.9 0.5 17.6 0.2% make production chunks chunking (2%)
53.1 1,875 28.3 0.0 7.7 0.2% collect mergeable modules compute merged modules (0%)
37.8 14 2696.7 9.7 11.3 0.1% apply effects write all entrypoints to disk (7%)
37.0 13 2847.3 9.8 11.2 0.1% write file apply effects (100%)
29.8 7 4253.0 15.0 17.6 0.1% compute merged modules make production chunks (100%)

Duration Distribution

Range Count Percentage
< 10us (noise) 1,082,907 65.3%
10us - 100us 548,514 33.1%
100us - 1ms 22,583 1.4%
1ms - 10ms 4,303 0.3%
10ms - 100ms 93 0.0%
> 100ms 5 0.0%

Action Items

  1. [P0] Use Batching Candidates to pinpoint specific files needing try_join or reduced #[turbo_tasks::function] limits.
  2. [P1] Inspect P95 (ms) for heavy monolith tasks. Focus on long-tail outliers rather than averages.

Report generated by Intelligent Utoopack Performance Analysis Agent

@xusd320 xusd320 merged commit cb23721 into next Mar 12, 2026
17 of 19 checks passed
@xusd320 xusd320 deleted the support-emotion-transform branch March 12, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants