From af29599f5fc99f186ab02c074f1525a36de44c8b Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 00:32:21 +0000 Subject: [PATCH] fix(loadable-components): skip transformation when ssr: false is specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Donny/강동윤 --- packages/loadable-components/src/lib.rs | 36 +++++++++++++++++++ .../input.js | 2 ++ .../output.js | 4 +++ 3 files changed, 42 insertions(+) create mode 100644 packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/input.js create mode 100644 packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/output.js diff --git a/packages/loadable-components/src/lib.rs b/packages/loadable-components/src/lib.rs index 636067d96..e55c85c51 100644 --- a/packages/loadable-components/src/lib.rs +++ b/packages/loadable-components/src/lib.rs @@ -127,7 +127,43 @@ where false } + fn has_ssr_false(&self, call: &CallExpr) -> bool { + let options = match call.args.get(1) { + Some(arg) => &arg.expr, + None => return false, + }; + + let obj = match options.as_ref() { + Expr::Object(obj) => obj, + _ => return false, + }; + + obj.props.iter().any(|prop| match prop { + PropOrSpread::Prop(prop) => match prop.as_ref() { + Prop::KeyValue(kv) => { + let is_ssr_key = match &kv.key { + PropName::Ident(i) => &*i.sym == "ssr", + PropName::Str(s) => s.value == "ssr", + _ => false, + }; + is_ssr_key + && matches!( + kv.value.as_ref(), + Expr::Lit(Lit::Bool(Bool { value: false, .. })) + ) + } + _ => false, + }, + _ => false, + }) + } + fn transform_import_expr(&mut self, call: &mut CallExpr) { + // Skip transformation if ssr: false is specified in the options + if self.has_ssr_false(call) { + return; + } + let import = { let mut v = ImportFinder::default(); call.visit_with(&mut v); diff --git a/packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/input.js b/packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/input.js new file mode 100644 index 000000000..f27e9be13 --- /dev/null +++ b/packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/input.js @@ -0,0 +1,2 @@ +import loadable from "@loadable/component"; +loadable(() => import("./OtherComponent"), { ssr: false }); diff --git a/packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/output.js b/packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/output.js new file mode 100644 index 000000000..539f69fe8 --- /dev/null +++ b/packages/loadable-components/tests/fixture/simple import/should not transform when ssr is false/output.js @@ -0,0 +1,4 @@ +import loadable from "@loadable/component"; +loadable(()=>import("./OtherComponent"), { + ssr: false +});