Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/loadable-components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines +141 to +145

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Respect later overrides when checking ssr: false

has_ssr_false() now returns true if any property in the options object is ssr: false, but JavaScript object literals are order-sensitive. Inputs like loadable(() => import('./Comp'), { ssr: false, ...opts }) or { ssr: false, ssr: true } end up with ssr !== false at runtime, yet this branch still skips the transform entirely. In those cases we silently drop the loadable SSR metadata even though SSR is effectively enabled.

Useful? React with 👍 / 👎.

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import loadable from "@loadable/component";
loadable(() => import("./OtherComponent"), { ssr: false });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import loadable from "@loadable/component";
loadable(()=>import("./OtherComponent"), {
ssr: false
});
Loading