Skip to content

Commit 4c82e78

Browse files
fix(loadable-components): skip transformation when ssr: false is specified (#592)
When loadable() is called with { ssr: false } in the options object, the plugin now skips the SSR transformation as required by the loadable-components API. Fixes #465 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
1 parent ac7669d commit 4c82e78

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

  • packages/loadable-components

packages/loadable-components/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,43 @@ where
127127
false
128128
}
129129

130+
fn has_ssr_false(&self, call: &CallExpr) -> bool {
131+
let options = match call.args.get(1) {
132+
Some(arg) => &arg.expr,
133+
None => return false,
134+
};
135+
136+
let obj = match options.as_ref() {
137+
Expr::Object(obj) => obj,
138+
_ => return false,
139+
};
140+
141+
obj.props.iter().any(|prop| match prop {
142+
PropOrSpread::Prop(prop) => match prop.as_ref() {
143+
Prop::KeyValue(kv) => {
144+
let is_ssr_key = match &kv.key {
145+
PropName::Ident(i) => &*i.sym == "ssr",
146+
PropName::Str(s) => s.value == "ssr",
147+
_ => false,
148+
};
149+
is_ssr_key
150+
&& matches!(
151+
kv.value.as_ref(),
152+
Expr::Lit(Lit::Bool(Bool { value: false, .. }))
153+
)
154+
}
155+
_ => false,
156+
},
157+
_ => false,
158+
})
159+
}
160+
130161
fn transform_import_expr(&mut self, call: &mut CallExpr) {
162+
// Skip transformation if ssr: false is specified in the options
163+
if self.has_ssr_false(call) {
164+
return;
165+
}
166+
131167
let import = {
132168
let mut v = ImportFinder::default();
133169
call.visit_with(&mut v);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import loadable from "@loadable/component";
2+
loadable(() => import("./OtherComponent"), { ssr: false });
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import loadable from "@loadable/component";
2+
loadable(()=>import("./OtherComponent"), {
3+
ssr: false
4+
});

0 commit comments

Comments
 (0)