Skip to content

refactor: support aliased and member runtime import shake#2437

Merged
HuJean merged 1 commit intomainfrom
p/refactor-shake
Apr 9, 2026
Merged

refactor: support aliased and member runtime import shake#2437
HuJean merged 1 commit intomainfrom
p/refactor-shake

Conversation

@HuJean
Copy link
Copy Markdown
Collaborator

@HuJean HuJean commented Apr 7, 2026

Summary by CodeRabbit

  • Bug Fixes

    • React transform now correctly recognizes aliased runtime imports and removes matching calls/params, including member calls invoked via default or namespace runtime imports, while preserving calls from other runtimes.
  • Tests

    • Added snapshots and coverage for aliased, default, and namespace import scenarios.
    • Updated compatibility/main-thread tests to reflect observable logging in effected cases.
  • Chores

    • Patch-level release entry for the React package.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@HuJean HuJean requested a review from gaoachao as a code owner April 7, 2026 13:43
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2026

🦋 Changeset detected

Latest commit: 5dd3785

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@lynx-js/react Patch
@lynx-js/react-umd Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 97a7ec73-051b-4add-bf1e-cf4046904617

📥 Commits

Reviewing files that changed from the base of the PR and between ee393fc and 5dd3785.

📒 Files selected for processing (16)
  • .changeset/fair-crews-lie.md
  • packages/react/runtime/src/renderToOpcodes/index.ts
  • packages/react/transform/crates/swc_plugin_shake/lib.rs
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
  • packages/webpack/react-webpack-plugin/src/loaders/options.ts
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
✅ Files skipped from review due to trivial changes (9)
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • .changeset/fair-crews-lie.md
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_call_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_param.js
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_param_by_local_name.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_params.js

📝 Walkthrough

Walkthrough

Records runtime import bindings per-local-identifier and expands the shake transform's call-matching to handle aliased named imports and member calls from default/namespace runtime imports; adds/updates SWC snapshot and webpack tests accordingly.

Changes

Cohort / File(s) Summary
Changeset & Metadata
\.changeset/fair-crews-lie.md
Adds a patch changeset documenting expanded shake.removeCall / shake.removeCallParams matching for aliased and member-form runtime imports.
Core Transform Logic
packages/react/transform/crates/swc_plugin_shake/lib.rs
Replaces boolean+Vec import tracking with HashMap<Id, String> (local id → imported name); rewrites import handling and expands should_remove_call to match aliased named imports and member calls on default/namespace imports (dot and computed properties).
SWC Snapshot Tests
packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/*
Adds fixtures covering aliased named-import removal, local-alias resolution, default/namespace member-call & param removal, and ensuring calls from other runtimes are preserved.
Webpack Plugin Tests (compat & main-thread)
packages/webpack/react-webpack-plugin/test/cases/...
Updates __runInJS compat expectations under __LEPUS__; replaces placeholder TODOs with console.info(...) in several main-thread use-effect and use-imperative-handle test callbacks.
Runtime renderToOpcodes
packages/react/runtime/src/renderToOpcodes/index.ts
Switches internal vnode/hook/dirty bookkeeping to use symbol-indexed fields ([DIRTY], [VNODE], [HOOK]) and refactors some typeof-based branches.
Webpack Loader Options
packages/webpack/react-webpack-plugin/src/loaders/options.ts
Extends main-thread shake.pkgName allowlist to include preact/hooks and preact/compat.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • gaoachao
  • colinaaa
  • luhc228
  • upupming

Poem

🐇 I mapped each import, local name in tow,
Aliases bowed where the runtime calls go.
Default and namespace, dotted or quoted,
Vanish the echoes the transform noted.
Hooray — tests hop in, tidy and slow.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: extending the shake transform to support aliased and member-style runtime imports in addition to direct named imports.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch p/refactor-shake

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@HuJean HuJean force-pushed the p/refactor-shake branch from fb1db2e to b9c2eb2 Compare April 7, 2026 13:47
@HuJean HuJean changed the title Support aliased and member runtime import shake refactor: support aliased and member runtime import shake Apr 7, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/react/transform/crates/swc_plugin_shake/lib.rs`:
- Around line 774-783: The test should_keep_use_effect_call_from_custom_runtime
contains a typo in the import specifier ("@lynx-js/custon-react-runtime");
update the import line inside that test's source string to
"@lynx-js/custom-react-runtime" so the package name matches the test name and
intent, i.e., fix the import specifier in the test string where useEffect is
imported.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98def1e1-da8a-4ccd-b53d-9b195c5368a5

📥 Commits

Reviewing files that changed from the base of the PR and between 1f4f117 and b9c2eb2.

📒 Files selected for processing (7)
  • .changeset/fair-crews-lie.md
  • packages/react/transform/crates/swc_plugin_shake/lib.rs
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 7, 2026

Merging this PR will degrade performance by 26.94%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 70 untouched benchmarks
⏩ 21 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
002-hello-reactLynx-destroyBackground 679.8 µs 930.5 µs -26.94%
transform 1000 view elements 47.3 ms 45.1 ms +5.07%

Comparing p/refactor-shake (5dd3785) with main (59d11b2)

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

React MTF Example

#279 Bundle Size — 206.07KiB (+0.01%).

5dd3785(current) vs 59d11b2 main#278(baseline)

Bundle metrics  Change 2 changes
                 Current
#279
     Baseline
#278
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 46.02% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 173 173
No change  Duplicate Modules 67 67
Change  Duplicate Code 45.76%(-0.02%) 45.77%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#279
     Baseline
#278
No change  IMG 111.23KiB 111.23KiB
Regression  Other 94.84KiB (+0.03%) 94.81KiB

Bundle analysis reportBranch p/refactor-shakeProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

React Example

#7146 Bundle Size — 236.82KiB (+0.01%).

5dd3785(current) vs 59d11b2 main#7145(baseline)

Bundle metrics  Change 2 changes
                 Current
#7146
     Baseline
#7145
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 38.44% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 179 179
No change  Duplicate Modules 70 70
Change  Duplicate Code 46.1%(-0.02%) 46.11%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#7146
     Baseline
#7145
No change  IMG 145.76KiB 145.76KiB
Regression  Other 91.06KiB (+0.03%) 91.03KiB

Bundle analysis reportBranch p/refactor-shakeProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

Web Explorer

#8721 Bundle Size — 730.24KiB (0%).

5dd3785(current) vs 59d11b2 main#8720(baseline)

Bundle metrics  Change 2 changes
                 Current
#8721
     Baseline
#8720
No change  Initial JS 43.63KiB 43.63KiB
No change  Initial CSS 2.16KiB 2.16KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 10 10
Change  Modules 148(-1.33%) 150
No change  Duplicate Modules 11 11
Change  Duplicate Code 34.69%(+0.03%) 34.68%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8721
     Baseline
#8720
No change  Other 385.55KiB 385.55KiB
No change  JS 342.53KiB 342.53KiB
No change  CSS 2.16KiB 2.16KiB

Bundle analysis reportBranch p/refactor-shakeProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 7, 2026

React External

#265 Bundle Size — 590.13KiB (-0.08%).

5dd3785(current) vs 59d11b2 main#264(baseline)

Bundle metrics  Change 1 change
                 Current
#265
     Baseline
#264
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 30.93% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#265
     Baseline
#264
Improvement  Other 590.13KiB (-0.08%) 590.57KiB

Bundle analysis reportBranch p/refactor-shakeProject dashboard


Generated by RelativeCIDocumentationReport issue

@HuJean
Copy link
Copy Markdown
Collaborator Author

HuJean commented Apr 8, 2026

@codex review

@HuJean HuJean force-pushed the p/refactor-shake branch from 0b2e9cc to 03e4446 Compare April 8, 2026 02:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03e44463d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@HuJean HuJean force-pushed the p/refactor-shake branch from 03e4446 to dc9dedd Compare April 8, 2026 02:06
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/react/transform/crates/swc_plugin_shake/lib.rs (1)

774-776: ⚠️ Potential issue | 🟡 Minor

Fix the package name typo in the custom-runtime keep-case.

@lynx-js/custon-react-runtime is confusing here and does not match the test name.

Proposed fix
-    import { useEffect } from "@lynx-js/custon-react-runtime";
+    import { useEffect } from "@lynx-js/custom-react-runtime";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react/transform/crates/swc_plugin_shake/lib.rs` around lines 774 -
776, The import string in the test named
should_keep_use_effect_call_from_custom_runtime contains a typo: change the
package name literal "@lynx-js/custon-react-runtime" to
"@lynx-js/custom-react-runtime" so it matches the test name and intended custom
runtime; update the import line within the test (the string in the r#"... import
{ useEffect } from ... "... block) to use the corrected package name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/react/transform/crates/swc_plugin_shake/lib.rs`:
- Around line 774-776: The import string in the test named
should_keep_use_effect_call_from_custom_runtime contains a typo: change the
package name literal "@lynx-js/custon-react-runtime" to
"@lynx-js/custom-react-runtime" so it matches the test name and intended custom
runtime; update the import line within the test (the string in the r#"... import
{ useEffect } from ... "... block) to use the corrected package name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2d819764-e973-4383-9582-6fc02b1b63d7

📥 Commits

Reviewing files that changed from the base of the PR and between b9c2eb2 and 03e4446.

📒 Files selected for processing (12)
  • .changeset/fair-crews-lie.md
  • packages/react/transform/crates/swc_plugin_shake/lib.rs
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
✅ Files skipped from review due to trivial changes (8)
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • .changeset/fair-crews-lie.md
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_param.js

@HuJean HuJean force-pushed the p/refactor-shake branch from dc9dedd to ee393fc Compare April 8, 2026 02:16
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/react/transform/crates/swc_plugin_shake/lib.rs`:
- Around line 191-212: The current check treats default and namespace imports
the same, allowing member-call removal for default imports (symbols: import_ids,
object_ident, imported_name, member.prop, target_calls), which is unsafe because
default-import objects can be reassigned; change the logic so the optimization
only runs for namespace imports (imported_name == "*") rather than both
"default" and "*", i.e., require imported_name == "*" before matching MemberProp
(MemberProp::Ident / MemberProp::Computed) and checking target_calls;
alternatively (if you prefer) implement reassignment tracking for default-import
properties, but for a minimal safe fix restrict to "*" only.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a2f99646-72a8-4b71-b344-faf8e16bb894

📥 Commits

Reviewing files that changed from the base of the PR and between 03e4446 and dc9dedd.

📒 Files selected for processing (12)
  • .changeset/fair-crews-lie.md
  • packages/react/transform/crates/swc_plugin_shake/lib.rs
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
✅ Files skipped from review due to trivial changes (7)
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
  • .changeset/fair-crews-lie.md
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/react/transform/crates/swc_plugin_shake/lib.rs (1)

197-200: ⚠️ Potential issue | 🟠 Major

Restrict member-call shaking to namespace imports.

import Runtime from "..."; Runtime.useEffect = keep; Runtime.useEffect() is valid, but this branch treats Runtime the same as a namespace import and strips the second call. That makes the transform unsound for default imports. The new default-import tests at Lines 725-766 should flip to keep/regression cases once this is fixed.

Minimal safe fix
-    // Only `default import` and `namespace import` can legally produce runtime member calls.
-    if imported_name != "default" && imported_name != "*" {
+    // Namespace imports are read-only module namespace objects.
+    // Default imports may reference mutable objects, so member-call shaking is unsafe there.
+    if imported_name != "*" {
       return false;
     }
In ECMAScript modules, can code mutate properties on an object received through `import foo from "mod"`? Are properties on `import * as ns from "mod"` effectively read-only/live bindings in the importing module?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react/transform/crates/swc_plugin_shake/lib.rs` around lines 197 -
200, The member-call shaking currently treats default imports like namespace
imports by checking imported_name != "default" && imported_name != "*"; change
the check so only namespace imports (imported_name == "*") are allowed to
produce runtime member calls, i.e., remove/default-exclude "default" from the
allowed set in the relevant branch in lib.rs (the variable imported_name and the
guard in the runtime member-call pruning logic). Update the tests referenced
(the new default-import tests at lines ~725-766) to flip to keep/regression
expectations once this restriction is applied.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/react/transform/crates/swc_plugin_shake/lib.rs`:
- Around line 197-200: The member-call shaking currently treats default imports
like namespace imports by checking imported_name != "default" && imported_name
!= "*"; change the check so only namespace imports (imported_name == "*") are
allowed to produce runtime member calls, i.e., remove/default-exclude "default"
from the allowed set in the relevant branch in lib.rs (the variable
imported_name and the guard in the runtime member-call pruning logic). Update
the tests referenced (the new default-import tests at lines ~725-766) to flip to
keep/regression expectations once this restriction is applied.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6bc982c4-df25-42b8-998a-d954485877e8

📥 Commits

Reviewing files that changed from the base of the PR and between dc9dedd and ee393fc.

📒 Files selected for processing (14)
  • .changeset/fair-crews-lie.md
  • packages/react/transform/crates/swc_plugin_shake/lib.rs
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_call_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_aliased_use_effect_param_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
  • packages/react/transform/crates/swc_plugin_shake/tests/__swc_snapshots__/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
✅ Files skipped from review due to trivial changes (7)
  • .changeset/fair-crews-lie.md
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_param.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_call.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_call_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_aliased_use_effect_param_by_local_name.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_keep_use_effect_call_from_custom_runtime.js
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_calls.js
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/react/transform/crates/swc_plugin_shake/tests/swc_snapshots/lib.rs/should_remove_default_and_namespace_runtime_import_params.js
  • packages/webpack/react-webpack-plugin/test/cases/compat/run-in-js/index.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/lynx-js-react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-effect/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/react.js
  • packages/webpack/react-webpack-plugin/test/cases/main-thread/use-imperative-handle/lynx-js-react.js

@HuJean HuJean force-pushed the p/refactor-shake branch from ee393fc to 5dd3785 Compare April 8, 2026 06:58
@HuJean HuJean requested review from Yradex and hzy as code owners April 8, 2026 06:58
@HuJean HuJean enabled auto-merge (squash) April 9, 2026 07:38
@HuJean HuJean merged commit fe90bb0 into main Apr 9, 2026
47 of 50 checks passed
@HuJean HuJean deleted the p/refactor-shake branch April 9, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants