fix(loadable-components): Support aliased loadable imports#585
Conversation
Make the 'from' field in Signature optional to allow matching any import with a specific name regardless of source package. This enables support for vendored or aliased loadable implementations. - Made Signature.from an Option<Wtf8Atom> - Updated visit_mut_import_decl to skip source check when from is None - Added test case for vendored loadable imports - Updated documentation with usage examples Fixes #572 Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
|
|
|
Code ReviewSummaryThis PR successfully addresses issue #572 by adding support for aliased/vendored imports. The implementation allows the plugin to transform calls regardless of their import source when configured with a signature that omits the Code Quality ✅Strengths:
Observations:
Testing ✅Strengths:
Suggestions:
vec![
Signature { name: "default".into(), from: None },
Signature { name: "lazy".into(), from: Some("@loadable/component".into()) }
]
Security Considerations ✅No security concerns identified:
Performance Considerations ✅Analysis:
Potential Issues & Edge Cases
Documentation ✅Strengths:
Minor suggestion: Best Practices ✅
Recommendation: APPROVE ✅This is a well-implemented feature that:
The implementation is production-ready. The minor suggestions above are optional enhancements, not blockers. |
Code ReviewSummaryThis PR successfully addresses issue #572 by adding support for aliased/vendored loadable imports. The implementation allows the plugin to transform loadable() calls regardless of their import source when configured with a signature that omits the from field. Code Quality ✅Strengths:
Observations:
Testing ✅Strengths:
Suggestions for additional test coverage:
Security Considerations ✅No security concerns identified:
Performance Considerations ✅Analysis:
Potential Issues & Edge Cases
Documentation ✅Strengths:
Minor suggestion: Best Practices ✅
Recommendation: APPROVE ✅This is a well-implemented feature that:
The implementation is production-ready. The minor suggestions above are optional enhancements, not blockers. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 05fc137bad
ℹ️ 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".
| ImportSpecifier::Default(default_spec) => { | ||
| if signature.is_default_specifier() { | ||
| self.specifiers.insert(default_spec.local.sym.clone()); |
There was a problem hiding this comment.
Check the local name before accepting any default import
In visit_mut_import_decl, a signature with from: None and name == "default" now adds every default import to self.specifiers because this branch never compares default_spec.local.sym to the configured binding name. That means the new README example with {"name":"loadable"} will never match import loadable from '...', while the only working config ({"name":"default"}) will also rewrite unrelated calls like import foo from 'foo'; foo(() => import('./X')). Please gate source-less default imports on the actual local identifier so the aliased-import feature neither misses intended imports nor over-matches others.
Useful? React with 👍 / 👎.
Summary
This PR fixes the issue where the @swc/plugin-loadable-components plugin would not transform
loadable()calls when imported from vendored or aliased packages.Changes
fromfield in theSignaturestruct optional (Option<Wtf8Atom>)visit_mut_import_declto skip source checking whenfromisNoneUsage
To enable aliased imports, configure with a signature that omits the
fromfield:This matches the behavior of the official Babel plugin as documented in the Loadable documentation.
Fixes #572
Generated with Claude Code) | View branch | [View job run](https://github.com/swc-project/plugins/actions/runs/21084641572